Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sun Sep 12, 2010 12:36 am   

@input.1 syntax
 
I am trying to revise and old script and I am not sure if I have the correct syntax anymore for CMUD.

#IF (%match( @input.1, ~[|~])) {
#VARIABLE emph @input.1



In the above the variable emph isn't being populated. If I do a #SHOW @input.1 is gives the correct values. Help please.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Sep 12, 2010 2:33 am   
 
The problem is your %match() pattern. You're testing if @input.1 = "[|]", rather than @input.1 = "[" or "]". This causes the #VARIABLE command to never fire.

To fix, you need {} and perhaps will need "" around all of it
_________________
EDIT: I didn't like my old signature
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sun Sep 12, 2010 3:37 am   
 
Okay.. Here is the issue. The mud I am playing will let you have emphasis in your communication.

say (with a smile) You can't do that.
Output: You say, with a smile, "You can't do that."

Now the mud parses the (). I want to capture those also into the variable.

Beginning of script:
#var channel %1
#var input %params(2)

when I show the @input variable it shows: with a smile You can't do that.

Now I know that I could put a ~ in front of the () to capture them, but I don't want to do that. Is there any way to capture the ()?
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Sep 12, 2010 4:21 pm   
 
Go look at the @input variable in the Package Editor. The () are already captured. The reason you don't see them in the show is because they are being evaluated as an expression. The only way to reveal the () in the show is to use %quote(), which puts a ~ in front of the ().
_________________
EDIT: I didn't like my old signature
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sun Sep 12, 2010 5:59 pm   
 
Matt when I look at the @input variable in the editor it shows: with a smile You can't do that.
The () are not captured. Do you have something disabled?

if I put the ~ in front of the () with my script like so:
stutter say ~(while smiling~) You can't do that.

It will capture the () in the @input variable. I don't want to have to put the ~ in front of them.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Sep 12, 2010 6:56 pm   
 
If you don't want to use ~ then use "":

stutter "(while smiling) You can't do that."

The issue is that CMud uses naked ()--that is, any parentheses that are not quoted or inside double-quotes--to denote expression evaluation. It's just like in a trigger where you have to quote parentheses when you want to match them because triggers use () to capture subpatterns into the %1...%99 variables.
_________________
EDIT: I didn't like my old signature
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sun Sep 12, 2010 7:20 pm   
 
I do know that information. I was just wondering if there was a way around it. I just didn't want to use the ~. Let me think about the using quotes instead.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sun Sep 12, 2010 11:17 pm   
 
Okay. I decided to use quotes to capture the () in the variable..
Now this is what I could have captured:

(nervously) I am not sure if I want to do that.
OR
(while smiling) I am not sure if I want to do that.

Here is what I want to do: I want to capture anything inside the parenthesis, including them and put into another variable and leave the rest in the input variable.

I've tried a few ways but I am having difficulty finding an easy way to do it..
Any ideas?
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
orphean
Apprentice


Joined: 21 Oct 2008
Posts: 147
Location: Olympia, WA

PostPosted: Sun Sep 12, 2010 11:36 pm   
 
Why not just use the subpattern capturing functionality of %match itself? For example, assuming @input was "(nervously) I am not sure if I want to do that." then this:

Code:
%match( @input, "(~(*~))(*)", exp1, exp2 )


would put (nervously) into @exp1 and " I am not sure if I want to do that." into @exp2. For the 'leave the rest in the input variable' part if you're talking about removing the text in the parenthesis from @input I would probably use %subregex, ie:

Code:
#var input %subregex(@input, "\(.+\)", "")


Would set @input to " I am not sure if I want to do that." removing the (nervously)
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Sep 13, 2010 4:34 am   
 
I used the %match function, but I don't want it to return a 1, because it sends it to the mud. Is there a way not to do that.

Here is some of the code:
Code:


#IF  (%begins(@input, "(") || %begins(@input, " " )) {
  //#print Enter in the input if statement
  %match( @input, "(~(*~))(*)", emph, sentence)
  }


When my script gets to the match function is displays a 1 to the screen.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
orphean
Apprentice


Joined: 21 Oct 2008
Posts: 147
Location: Olympia, WA

PostPosted: Mon Sep 13, 2010 6:36 am   
 
Whenever a function returns a value you don't want to pass on just assign the result to a local variable:

Code:
$gag = %match( @input, "(~(*~))(*)", emph, sentence)


In this case you're just interested in the sideaffect of the %match function (populating your variables) and don't really care about the boolean value it returns (which it needs to return to be useful in #if statements), so just slap that value into a variable that you do nothing with. Smile
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Sep 13, 2010 12:27 pm   
 
Alternatively, use the #CALL command: #CALL %match(...
The problem with your code was that you were starting a command line with a % function. You should never do that. This was frequently done in Zmud, but you should avoid this practice in Cmud. Starting a command line with a function can lead to many problems, and even break your code. Instead of starting a command line with a function, start it with the appropriate command--some of the choices are: #CALL, #SEND, #EXEC, #SAY. (Don't use #NOOP--this is denigrated in Cmud).
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net