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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
JMinara
Beginner


Joined: 05 Jul 2005
Posts: 14

PostPosted: Fri Nov 03, 2006 3:15 am   

How do I do named arguments in triggers?
 
I searched but couldn't find anything about how to create named local variables automatically in triggers..

Anyone know?
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Nov 03, 2006 4:00 pm   
 
If you are asking about named parameters in triggers as is possible with aliases, then no it is not possible. You simply need to assign you pattern matches to the local variable you desire. For example
Code:
$myData=%1
_________________
Asati di tempari!
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Nov 03, 2006 5:49 pm   
 
Actually, named arguments in triggers *is* implemented. The syntax was mentioned in a thread a while ago in the forum, but hasn't been added to the help file. The syntax is:

($localvar:...)

For example, to capture a number and store it in the $hp local variable, you could have a trigger pattern like this:
Code:
($hp:%d)

Then in your trigger script, you can refer to $hp to retrieve this captured number.
Code:
#trigger {($hp:%d)} {#SHOW $hp}

This syntax was chosen because it's very similar to the named argument syntax in Perl regular expressions (where a ? is used instead of the $)
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Nov 03, 2006 7:09 pm   
 
Thanks for the correction Zugg... I vaguely remember seeing that thread. As a matter of fact I could use that syntax myself to speed up a few triggers. Now the next question is, is the format the same if you are doing regular expression patterns?
_________________
Asati di tempari!
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Nov 03, 2006 8:34 pm   
 
Maybe. I haven't tested this with regular expression triggers. The named argument syntax is handled at trigger compile time, and not at runtime. So, the named arguments *should* be stripped from the pattern regardless of whether or not it has the regex option checked. So try it and let me know.
Reply with quote
JMinara
Beginner


Joined: 05 Jul 2005
Posts: 14

PostPosted: Sat Nov 04, 2006 7:30 am   
 
Zugg: You can only have one named variable in a trigger. If there's more than one, the trigger tosses an error and won't compile saying invalid local variables
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Sat Nov 04, 2006 5:48 pm   
 
Hmm, that's wierd. I've confirmed that problem and added it to the bug list. Don't know what happened...it *used* to work. Sigh.
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Mon Nov 13, 2006 3:13 pm   
 
Can this same syntax be used with #REGEX triggers? I'm having difficulty finding a solution that works. The parser tells me that the local variable is invalid.

Code:
#REGEX {^($hp:\d+)h\, ($mp:\d+)m} {#say HP: $hp  MP: $mp} "" {nocr|prompt}


I tried (?hp:\d+) and (?$hp:\d+), too.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Nov 13, 2006 3:30 pm   
 
The bug with triggers not liking more than one named argument still isn't fixed, that might have something to do with your problem Larkin ;)
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Mon Nov 13, 2006 3:32 pm   
 
This problem is different. It's not even parsing the syntax to create the trigger. Using just one local variable still doesn't work with regex...
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Nov 13, 2006 8:37 pm   
 
Unfortunately the syntax isn't supported with the #REGEX command itself. If you create a trigger in the settings editor and then mark it as a regular expression, then you can use the named arguments. So it's just a problem with the #REGEX command on the command line since it doesn't parse the pattern argument. The command line parser currently only understands the zMUD pattern syntax and doesn't have a parser for regular expressions on the command line, so regular expressions are just treated as literal strings. This prevents the named arguments from being recognized.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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