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
xsl
Newbie


Joined: 05 Oct 2011
Posts: 3

PostPosted: Wed Oct 05, 2011 11:15 pm   

using element of list inside trigger
 
Couldn't find anywhere answer, so decided to ask.

I've got two lists:

@varFraglist {name1|name2|name3}
@varFraglistreason {reason1|reason2|reason3}

And i got trigger:

<trigger priority="7960" id="796">
<pattern>{@varFraglist}</pattern>
<value>#cw red;
#sh Reason for frag: %item(@varFraglistreason,%ismember(%1,@varFraglist));</value>
</trigger>

There's a %1 in trigger, so second line doesn't work. The purpose of this trigger is to change color of player, and notice me with a reason.
How should i write it, so i could use one name, that made trigger to fire?

P.S. Names can be one, two, or three words, and must be catched inside one line (sometimes multiply times).
Example of mud text:

Somewhere in city.
Your totaly lost in city. You have no idea where to go.
You see four exits: north, east, south, west.
Short bald dwarf, blackdressed man, grayhaired old dwarf, Frank, high priest, Mike.
>
Reply with quote
ins0mnia
Novice


Joined: 23 Jan 2011
Posts: 42
Location: United States

PostPosted: Wed Oct 05, 2011 11:42 pm   
 
You aren't using strings properly, you need to capture the names to compare to your list like

<trigger priority="20950" id="2095">
<pattern>^You see %w exits:</pattern>
<trigger type="Within Lines" param="1">
<pattern>^(*)$</pattern>
</trigger>
</trigger>

then do %ismember etc etc.

A database variable would make this easier, #VAR varFraglist {name1=reason1|name2=reason2|name3=reason3}

then it's #sh Reason for frag: %db(@varFragList, "name" )
Reply with quote
xsl
Newbie


Joined: 05 Oct 2011
Posts: 3

PostPosted: Thu Oct 06, 2011 7:41 am   
 
The patten to this trigger must be name only.
If one of (150) 'names' is 'grayhaired old dwarf' and the second one is 'Mike' the trigger must color them both in one line (that it does), but i need it to text me also corresponding values from second list (the same, if i'll make it a database variable).

Propably i need to use local variable or something? Is there a possibility to declare one in trigger?

Edit:
Made something (working for now) like this:

<trigger priority="7960" id="796">
<pattern>($temp:{@varFraglist})</pattern>
<value>#cw firebrick;
#sh Fragreason: %item(@varFraglist_com,%ismember($temp,@varFraglist))</value>
<arglist>$temp</arglist>
</trigger>

Should i expect problems with that code, or is it o.k.?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Oct 07, 2011 2:30 pm   
 
You should be able to do what you want with a database variable. Make a db variable like so:
#VAR FragDB {name1=reason1|name2=reason2|name3=reason3}

Then the trigger is:
#TRIGGER {({@FragDB})} {#CW firebrick; #SH Fragreason: %db(@FragDB,%1)}}

(there is a command line option for setting it to repeat within line, but I forget what it is. You can set the repeat within line from the Package Editor.)

Something like your last code should work, but you probably don't need the $temp. The reason your original code didn't work is probably because you didn't put parentheses around the {}, so it was not captured into %1.
Reply with quote
xsl
Newbie


Joined: 05 Oct 2011
Posts: 3

PostPosted: Fri Oct 07, 2011 3:23 pm   
 
Trigger works very well, just got one more remark:
trigger does not work after i put it in package file, i need to restart cmud for it work.

Thank You for Your help!
Reply with quote
ins0mnia
Novice


Joined: 23 Jan 2011
Posts: 42
Location: United States

PostPosted: Fri Oct 07, 2011 4:27 pm   
 
Hm I didn't know it was so easy to match within a string/db variable, I figured it would need to match the entire variable not just an element. Nice.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Oct 07, 2011 4:41 pm   
 
Yes, it's very convenient. Within a trigger, {@dbvar} will match against the _keys_ of @dbvar, and if you capture the value, it captures the matched key. Makes a lot of things much easier.
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