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
apfinger
Novice


Joined: 19 Nov 2006
Posts: 40

PostPosted: 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
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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)}
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: 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
Reply with quote
apfinger
Novice


Joined: 19 Nov 2006
Posts: 40

PostPosted: 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.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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)}
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
apfinger
Novice


Joined: 19 Nov 2006
Posts: 40

PostPosted: 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.
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