|
apfinger Novice
Joined: 19 Nov 2006 Posts: 40
|
Posted: Sun Mar 11, 2007 7:43 pm
Help deleting from a list |
In a trigger, I am trying to remove a value from my list, BerserkMode, if it's the next item in my list, LocketSpecTypes.
%if( %ismember( D, @LocketSpecTypes)==0, BerserkMode=%delitem( "D", @BerserkMode))
LocketSpecTypes = %delnitem(@LocketSpecTypes,0)
When I use this line, BerserkMode=Fury is sent to the MUD, rather than managed by zMUD. Any suggestions how to get zMUD to execute the command?
The two lists would look something like this:
BerserkMode = D|Fury
LocketSpecTypes = D|D|S|H|D
Running the above command, I would expect
BerserkMode = Fury
LocketSpecTypes = D|S|H|D |
|
Last edited by apfinger on Sun Mar 11, 2007 8:44 pm; edited 1 time in total |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Mar 11, 2007 7:59 pm |
Use the #if command rather than the %if function. The function will just return a value, you need to use the command to actually execute something.
#if (%ismember(D,@LocketSpecTypes)=0) {BerserkMode=%delitem("D",@BerserkMode)} |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sun Mar 11, 2007 8:02 pm |
I think you are mixing up commands and functions in ZMud. Use #IF for your conditional instead of %if().
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
apfinger Novice
Joined: 19 Nov 2006 Posts: 40
|
Posted: Sun Mar 11, 2007 9:09 pm |
I changed the command to:
#IF ( %ismember( D, @LocketSpecTypes)==0) {BerserkMode=%delitem( "D", @BerserkMode)} {#ECHO %ismember( D, @LocketSpecTypes)}
LocketSpecTypes = %delnitem( @LocketSpecType, 0)
When I set BerserkMode to D|Fury and LocketSpecTypes to D and force the trigger with #ECHO (trigger text), the #IF fails, resulting in
#ECHO 1
BerserkMode is still D|Fury, while LocketSpecType is empty.
If I force the trigger again with a #ECHO (trigger text), the #IF passes and BerserkMode changes to Fury.
I'm a bit confused why #IF doesn't pass until the second time around, while %if passes the first time but does not execute the command in the true scenerio. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Mar 11, 2007 9:26 pm |
Because you're checking if %ismember(D...) is zero - that is, if D is not a member of @LocketSpecTypes. Since you yourself set it to D, it obviously contains D and so the #if will evaluate false and run the false command. The second time through, D has been removed from @LocketSpecTypes through the second line, so the #if will evaluate true. If you want to check if D is a member of @LocketSpecTypes and delete "D" from @BerserkMode if this is the case, then do this:
#if (%ismember(D,@LocketSpecTypes)) {BerserkMode=%delitem("D",@BerkserkMode)} |
|
|
|
apfinger Novice
Joined: 19 Nov 2006 Posts: 40
|
Posted: Sun Mar 11, 2007 10:14 pm |
That would do it - I'm used to arrays starting their item lists at 0 rather than 1. Thanks for pointing that out - it works now.
|
|
|
|
|
|