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
sda
Wanderer


Joined: 18 Apr 2001
Posts: 55
Location: United Kingdom

PostPosted: Sun Nov 10, 2002 1:26 am   

General Questions
 
Hello

1.
Which of the following is correct? My question is when should I be using %eval, and when not?

#IF (@hp>%eval(@maxhp-50)) {#NOOP}
#IF (@hp>(@maxhp-50)) {#NOOP}


2.
How should you declare a variable to be false, if you're being technically correct?

#VARIABLE myvar FALSE
#VARIABLE myvar 0
#VARIABLE myvar ""
#VARIABLE myvar {}


3.
If you are working with variables which are specific to a particular script, is it OK to undeclare them when the script finishes, even though the script runs very regularly (ie. every 2 seconds), or will this eventually cause Zmud to have memory allocation errors? I like to keep my variables all in the same class folder so I can find them easily, and when I'm examining/editing my scripts, I don't want to sift through too many unimportant variables.

#UNVAR myvar


Thanks,
Steve ;)
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sun Nov 10, 2002 1:50 am   
 
1. They both work. The first parameter to #IF is an expression, zMUD automatically evaluates it. You don't need to use %eval, but it won't hurt anything if you do.
This took about a minute to test, I'm a slow typer.

2. Depends on what else you intend to do with the variable. If it's just being used to track a true/false state I prefer 1 for true and 0 for false. If I'm planning to use the variable to concatenate strings or as an item list or record variable, I'd probably use a null string for false. Three common ways of assigning null strings are:
#VAR myvar ""
#VAR myvar {}
#VAR myvar %null
They all work identically, which you use is a matter of personal preference.
I haven't had much success with on/off, true/false, yes/no, but I haven't made any effort to use them other than for testing.

Personally, I don't really care very much about what's "technically correct", I'm much more interested in "what works?".

3. I haven't had any problem with removing variables, however I don't do it on a wholesale basis the way you're suggesting. I suspect you'll have to be the one to provide the answer to this question.

LightBulb
Senior Member
Reply with quote
sda
Wanderer


Joined: 18 Apr 2001
Posts: 55
Location: United Kingdom

PostPosted: Sun Nov 10, 2002 2:04 am   
 
Thanks Lightbulb

One further question, because the %eval function exists, I presume that some commands in Zmud automatically evaluate and some don't. Do you know any of the obvious ones?

Thanks,
Steve ;)
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sun Nov 10, 2002 2:22 am   
 
From the helpfile topic Advanced Topics, subtopic Advanced Programming:

{quote}
When commands are executed, the type of each parameter determines whether the parameter will be expanded, evaluation, or left alone. For nitty-gritty details of the zMUD Programming syntax, read the zMUD Programming Language Manual on the web at http://www.zuggsoft.com/zmud/prog.htm .
For example, the #VAR command takes a String parameter, which is expanded, so

#VAR temp 5 assigns the number 5 to the variable temp

#VAR hp {100/@temp}

#SHOW @hp displays 100/5

However, the #MATH command takes an Expression which is evaluated, so

#VAR temp 5 assigns the number 5 to the variable temp

#MATH hp 100/@temp

#SHOW @hp displays 20

The #FUNC command takes a Literal which is left alone, so

#VAR temp 5 assigns the number 5 to the variable temp

#FUNC hp 100/@temp

#SHOW @hp displays 100/@temp
{end quote}

I'd strongly recommend you look at the website mentioned.

LightBulb
Senior Member
Reply with quote
sda
Wanderer


Joined: 18 Apr 2001
Posts: 55
Location: United Kingdom

PostPosted: Sun Nov 10, 2002 2:45 am   
 
Thankyou LightBulb - I will definately take a look there.

Steve :)
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