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


Joined: 10 Oct 2000
Posts: 4
Location: USA

PostPosted: Fri Mar 15, 2002 3:33 pm   

Problem with %if %ismember functions together
 
I have a variable that stores the spells ups that have currently gone out. These spells are added when they go out and taken off the list when they are successfully cast (@SpellList). When I enter into combat with the 'invis' spell on, it automatically goes out. I need to recast this spell when I get out of combat. I tried various combinations of and if statement with an imbeded ismemeber to check the @SpellList variable after the fight to see if 'invis' is already listed in the variable. If the spell is in the variable, I want it to do nothing (aka #Noop). If the spell is not in the variable, I want it to add it to the list. I read the help files and tried to accomplish this by using the following format within my end of battle trigger (This info is from the help files, and does not reflect my exact function):

#IF %ismember(@petitioner,@friendsList) {cast heal @petitioner} {say Nope.}

Every time I try these two function together, I usually get all of the items listed in the variable as output to the mud. It looks like this:

ices|fly|invis

I am currentlly using the most recent beta. Any help that I can get is much appreciated. Thanks ahead of time.

Marrow


Marrow
Reply with quote
Carabas
GURU


Joined: 28 Sep 2000
Posts: 434
Location: USA

PostPosted: Fri Mar 15, 2002 4:47 pm   
 
Hmm, not certain why that is happening for you, but here are a couple of examples you can play with.

#IF (!%ismember(invis,@SpellList)) {SpellList=%additem(invis,@SpellList)}

However, if you just use the #ADDITEM command, no duplicates will be added.

^You receive %d experience points -> #ADDITEM SpellList invis

Also, I suggest you take a look at the %dups function. It will remove duplicate strings from a list.


Carabas
------
I like work; it fascinates me. I can sit and look at it for hours.
- Jerome K. Jerome
Reply with quote
Marrow
Newbie


Joined: 10 Oct 2000
Posts: 4
Location: USA

PostPosted: Fri Mar 15, 2002 6:13 pm   
 
Let me give an example of #additem adding duplicate items to the list:

1. Kill mob #1
2. Trigger runs and adds 'invis' to @SpellList
3. Cast 'invis' unsuccessfully
4. Kill mob #2
5. Trigger runs and adds 'invis' to @SpellList (2nd time)
6. Cast 'invis' successfully
7. Check @SpellList and one 'invis' is still there (which it should)

My reasoning for running the #if %ismember is to see if 'invis' is already in the variable before adding it. If it is there, there is no reason to add it. The only way I can get the function to work, is if I take out the #if %ismemeber portion and just use the %additem (but this runs the chance of placing multiple 'invis' in the @SpellList).

Carabas, your example, unless i am mistaken, adds 'invis' if it is already found in the @SpellList. I want it to be added if it is not in the @SpellList. Thanks again for any help that anyone has for me.

Marrow
Reply with quote
Charbal
GURU


Joined: 15 Jun 2001
Posts: 654
Location: USA

PostPosted: Fri Mar 15, 2002 6:59 pm   
 
#IF (!%ismember(invis,@SpellList)) {SpellList=%additem(invis,@SpellList)}

executes if %ismember(invis,@SpellList) is 0; that is, if "invis" is not in the spell list. So it will add only if not already in the list.

From the help file on #ADDITEM: "Duplicated values are not added using this command."


I'd just do something like Carabas said:

#trigger {^You receive %d experience points} {#ADDITEM SpellList invis}

As for the problem of outputting your stringlist to the MUD, it'd probably be easier if we had some idea of what your code looks like.

 - Charbal
Reply with quote
Marrow
Newbie


Joined: 10 Oct 2000
Posts: 4
Location: USA

PostPosted: Fri Mar 15, 2002 9:17 pm   
 
I have seen the error of my ways. I thought that %additem and #additem did the same thing. I now see that %additem adds duplicates, and #additem does not add anything if the item is already in the list.

Both of you have been very helpful. I appreciate it.

Marrow
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