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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
john_taylor_jr
Wanderer


Joined: 17 Jan 2003
Posts: 57
Location: USA

PostPosted: Sat Dec 27, 2003 1:26 am   

Find out what matched
 
Ok I have a trigger like this
#CLASS {Bot}
#VAR hunt {keeper|paladin|guard}
#VAR avoid {warlock|witch|grimlin}
#TRIGGER {^(*) are here.$} {
#IF ("%1" =~ {@hunt}) {kill=1} {kill=0}
#IF ("%1" =~ {@online}) {kill=0}
#IF ("%1" =~ {@avoid}) {kill=0}
#IF ((@bot = 1) & (@kill=1)) {k @monster}
}
#CLASS 0
The @online is a list of players on the mud.
I was wondering if their were a way to find out which @hunt strings were matching
and then I could deal with setting @monster accordingly
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Dec 27, 2003 8:05 pm   
 
Why not just set @monster to %1 in the #IF for that list in the trigger? Unless there is overlap between the lists (which will definitely cause problems with your #IF commands), you should already know what list is matched simply by having that #IF condition evaluate to true.
Reply with quote
john_taylor_jr
Wanderer


Joined: 17 Jan 2003
Posts: 57
Location: USA

PostPosted: Sun Dec 28, 2003 2:18 am   
 
The %1 would be something like
Two keepers and Goblin are here.
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: Mon Dec 29, 2003 6:15 pm   
 
You could do something like this:
#LOOP %numwords(%1) {#IF (%ismember(%word(%1,%i),@hunt)) {#say %word(%1,%i) is a match!;#var monster {%word(%1,%i)}}}

Danlo
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Dec 29, 2003 9:48 pm   
 
You certainely can. The syntax for using the pattern matching operator supports capturing of matches as well. A few changes and your good to go
#CLASS {Bot}
#VAR hunt {keeper|paladin|guard}
#VAR avoid {warlock|witch|grimlin}
#TRIGGER {^(*) are here.$} {
#IF ("%1" =~ "({@hunt})") {kill=1;monster="%%1"} {kill=0}
#IF ("%1" =~ {@online}) {kill=0}
#IF ("%1" =~ {@avoid}) {kill=0}
#IF ((@bot = 1) & (@kill=1)) {k @monster}
}
#CLASS 0

The red " are necessary to tell the parser that the () are part of the pattern. I believe further expansion will be preformed on the @hunt variable, if you have trouble you know where to ask.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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