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


Joined: 23 May 2004
Posts: 14

PostPosted: Wed Oct 19, 2005 12:34 am   

LOOPDB, expansion of %{key} in a variable name
 
Basically, the part I'm having issues with is this

#LOOPDB @afflictions {
#ECHO %key %val
#IF (!@HerbBalance/herbbal AND @HerbBalance/%{key} = 1) {
#echo Should have eaten!
%exec( %val)
HerbBalance/herbbal = 1
}

The variable afflictions is a DB variable with an affliction->cure method. I have a variable for each affliction stored inside the HerbBalance class, thus when it loops through @afflictions, it should check to see if HerbBalance/herbbal = 0 and if HerbBalance/(whatever the current affliction name in the loop is) = 1, however, it doesn't seem to check, because I can't get it to echo "Should have eaten!", or even execute the commands. It lists the affliction then cure just fine, which is shown by #ECHO %key %val, but once it gets the the if, it just won't read it. What do you suggest?
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Wed Oct 19, 2005 2:52 am   
 
Untested but try this

@{HerbBalance/%key}
or
@{HerbBalance/%{key}}
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Oct 19, 2005 8:09 am   
 
Also the "%exec(%val)" should be "#EXEC %val".
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Winger
Beginner


Joined: 23 May 2004
Posts: 14

PostPosted: Wed Oct 19, 2005 12:35 pm   
 
The #exec bit was helpful, but the first suggestion did nothing. When I used @{HerbBalance/%{key}} it gave me a syntax error and wouldn't work, and when I used {@HerbBalance/%{key}} it returned every one as true.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Oct 19, 2005 8:51 pm   
 
I just tested Nexela's suggestion of "@{HerbBalance/%key}" and it worked perfectly. Both of Nexela's suggestions are actually valid syntax. In my testing the only way you would have a problem retrieving the variable data is the presence of a disallowed character (a-z A-Z - _ and 0-9 are only allowed in variable names).

Also you should use grouping parenthesis in your #IF expression. While I am sure you mean "((!@HerbBalance/herbbal) AND (@HerbBalance/%{key} = 1))" and this follows the order of operations as specified in the help for Expressions I find it to be best to always be explicit about these things; no matter what language you are working with.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Wed Oct 19, 2005 9:39 pm   
 
Cury braces {} in zscript are used for grouping. They follow the same principals of Parenthesis () in math in that the innermost set will be expanded first.

@HerbBalance/%{key}
Will expand (I believe. this part could be a little off due to using the class/var notation) like this. assuming Herbbalance is a class and %key="anything"
1. @Herbalance becomes %null (nothing nada zip (unless you also have a variable called herbbalance).
2. {%key} expands out to "anything"
3. Which finnaly becomes %null/"anything" which is an invalid math statement :P


@{HerbBalance/%{key}}
Will expand like this in a nutshell

1. becomes @{Herbalance/anything}
2. becomes the value of the variable anything in the herbalance class

I use this same principal in a math/comparative intensive script comparing mutiple datarecords and it had me thinking it couldnt be done when I first started until I remember reading somewhere about {}.
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Winger
Beginner


Joined: 23 May 2004
Posts: 14

PostPosted: Thu Oct 20, 2005 3:48 am   
 
Oddly enough
@{HerbBalance/%key}
Gives me a syntax error in the editor, but still works in practice. Perhaps this is a bug and should be edited out as a syntax error? I dunno.
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Thu Oct 20, 2005 7:05 pm   
 
I write lots of aliases that appear to have syntax errors when viewed in the settings editor, but they all work in practice. You'll see this primarily with <>, [], and {} grouping or expansion.
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