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

Joined: 09 May 2016
Posts: 6

PostPosted: Sat Sep 17, 2016 10:32 am   

Cross checking multiple variables
Is there a better way to cross check multiple variables to 1 name, than using an IF statement for each variable to check?

Say I have 30 variables, all with 1 name in each or empty(nothing else). Then I want to see if a captured %1 name matches any of those. Is there a better method to do that, than writing out 30 IF statements? The names for the variables change with any new group.

Say something like this instead

#IF (%1="var1, var2, var3, var4......") {} {}

Instead of 30 IF statements. Then if there is a way, is there a surefire method to determine which variable matches the %1. So I can then use the var instead of %1? For at the end I would need to know which variable matched the %1, to further my script.

Reply with quote

Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Sep 17, 2016 11:14 am   
I am not sure what you are keeping in those variables, but you should be able to keep them all in a single record variable. See the commands #ADDKEY #DELKEY and the function %db.

Alternately you can keep you current variables and maintain a list of the variables in another variable. See the commands #ADDITEM #DELITEM #FORALL and the functions %ismember %additem %delitem %item
%ismember is likely the closest match to what you asked for with the least additional work.
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote

Joined: 04 Aug 2002
Posts: 3514
Location: Pensacola, FL, USA

PostPosted: Sat Sep 17, 2016 12:55 pm   
If this were CMUD I would suggest a #SWITCH.
For zMUD i was thinking along what Vij said.
Windows 10 Home Premium 64-bit
AMD Phenom II x6 1055T 2.8GHz 16GB
CMUD Pro v3.34
Reply with quote

Joined: 03 Jan 2008
Posts: 48

PostPosted: Sun Sep 18, 2016 11:25 am   
The simplest way to do what you want, as far as matching goes, is #IF (%ismember(%1,@var1|@var2|@var3|@var4)) {do some nonsense} {do some other nonsense}. I use this to block certain things from going to my chat window so I know it works. The only way to find out what it matched, would be to save your %1 in another variable before the if statement, so it would end up looking more like:

var0=%1;#IF (%ismember(@var0, @var1|@var2|@var3|@var4));#show @var0

That will show you what var0 got set to which should tell you what it matched. I don't know of anyway to tell you what var specifically was matched though. If we knew more about what you were trying to do, we could help you more.
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