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
Vittorio
Beginner


Joined: 22 Oct 2003
Posts: 10

PostPosted: Fri Dec 12, 2003 7:11 am   

Question about function
 
Would appreciate if anyone can help me with this problem. I wish to create a function variable that returns 1 or 0. It takes %line2 as a parameter; ie. @linecheck(%line2). What it does is match the line against certain patterns. If there is a match, the variable returns true. If not, it returns false.

%line2 should match only one of the following 3 patterns:
You eat*
%w invokes the powers of %w ~and lays %w hands on you.
You touch the tree of life tattoo.

Now I initially tried a nested %if statement (nested to simulate short-cicuit evaluation):

%if( %1=~ "You eat", 1, %if( %1=~ "%w invokes the powers of %w ~and lays %w hands on you.", 1, %if( %1=~ "You touch the tree of life tattoo.", 1, 0)))

However, it appears I cannot use the =~ pattern matching for the nested %if's.. it does not evaluate properly and returns false (the second and third patterns are never checked). Can someone explain why?

I would also appreciate it if someone could suggest any way to streamline it. I thought about putting all the patterns into one string variable, @patterns= "You eat|invokes the powers of|You touch the tree of life" and reduce matching to one %pos operation rather than n %if's. That obviously has flaws, because the wildcards aren't recognized. Can something like that be done?


- V.
Reply with quote
Serentus
Apprentice


Joined: 28 Sep 2001
Posts: 103
Location: USA

PostPosted: Fri Dec 12, 2003 12:03 pm   
 
I was able to get it working this way

%if((%1=~"You eat *" or %1=~"%w invokes the powers of %w ~and lays %w hands on you." or %1=~"You touch the tree of life tattoo."),1,0)

That a pretty neet way check your cure. I just may have to steal that from you. :) much smoother than my current way.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Dec 12, 2003 7:26 pm   
 
If you intend to use multi-word strings, DEFINE it as a SINGLE item. Put "s around it.
#FU linecheck {%if( "%1" =~ "You eat", 1, %if( "%1" =~ "%w invokes the powers of %w ~and lays %w hands on you.", 1, %if( "%1" =~ "You touch the tree of life tattoo.", 1, 0)))}
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