|
msew Newbie
Joined: 11 Jun 2002 Posts: 9
|
Posted: Wed Jul 17, 2002 6:33 am
zmud documentation and suffering pain |
Why is the zmud documentation so woeful? :-)
Looking at the #IF documentation it says that an #IF is:
Syntax: %if(expression,true-value,false-value)
after fighting for some time and looking for sample code on the forums I find out that the #IF is actually like old school tintin and you can do it like: (we get to choose between % and # also it seems! GRAH!!!)
#IF { "foo" = @strValue} {#SHOW yes} {#SHOW no}
or
%IF { "foo" = @strValue} {#SHOW yes} {#SHOW no}
and lo and behold this is soooo far superior to the comma seperated "syntax" as you can actually do the above statement, while if you use commas you can't. (ie #IF ( "foo" = @strValue, #SHOW yes, #SHOW no) fails ). Why does the documentation show the comma syntax?
It seems that zmud is going down the terrible path that PERL went down and has like 30000 ways to do something. All with different syntax and massive differences in functionality. People on the boards do things one way and the documentation does things completely opposite.
Coming back to my registered Zmud after a number of years of not mudding, it is really painful to spend 45 minutes trying to get something to work to find out that the documentation is either outdated or just suggesting a very poor way to do things.
:-(
Does anyone out there have have a web site that has good examples of zmud code? :-) Heck it seems like there are 5 ways to access a variable depending on where you are and what you are doing and what syntax you are using and maybe even the time of the day. It is pretty painful.
msew |
|
|
|
Charbal GURU
Joined: 15 Jun 2001 Posts: 654 Location: USA
|
Posted: Wed Jul 17, 2002 10:46 am |
I have actually found the zMUD documentation to be remarkably complete and invaluable.
As for your #IF issue, the basic problem is that there are two types of zScript routines in zMUD: commands and functions.
Functions (indicated by a %) return a value, commands (indicated by a #) don't.
So
#IF (0 = 1) {#SAY Uh-oh...} {#SAY Whew! That was close.}
The comma syntax you refer to is for the %if function, not the #IF command above.
Since functions just return a value, they don't execute like commands; in particular, the true-value and false-value arguments cannot be commands themselves (as these wouldn't return a result so the function itself couldn't).
So, you could do something like
#show %if("foo" = @strValue, "yes", "no")
As for the 5 different ways to access a variable, maybe I can help clear it up:
@VariableName
Returns the value of a variable
VariableName alone
Used as an argument for some commands (e.g., #VARIABLE, #ADDITEM). Also used in equals sign assignment.
Some examples:
#VAR VariableName "Hello"
VariableName = "Test"
#ADDITEM VariableName "Item1"
@VariableName.Field
If VariableName is a database variable, returns the value of the field called Field.
If ptrVar is the string "VariableName",
@{@ptrVar}
Returns the value of the variable whose name is contained in the ptrVar variable (in this case, the value of the VariableName variable)
That's only four, but some of these can be mixed and matched (@{@ptrVar}.Field, for example).
Some things to check out:
A good synopsis of the zScript programming language: http://www.zuggsoft.com/library/book5/programming.htm
Helpfile documentation for #IF: http://www.zuggsoft.com/zmud/help6/IF.htm
Helpfile documentation for %if: http://www.zuggsoft.com/zmud/help6/if_.htm
- Charbal |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Wed Jul 17, 2002 4:42 pm |
There is an if function, %if. It's syntax is:
Syntax: %if(expression,true-value,false-value)
There is also an IF command. It's syntax is:
Syntax: #IF expression true-command [false-command]
You can do commands with %if by using the %exec function, but #IF is simpler.
I use both %if and #IF in my scripts. #IF is usually preferable, but there are cases where it's easier to accomplish a task with %if (such as changing colors in the middle of a line). I almost always use #VAR to create and change variables. I'm aware of the alternate forms but only use them if they actually do something different (#ADD, #MATH, #ADDITEM, etc.). Using a consistent style helps me read, understand, and debug my own scripts.
Commands can be found in the index but, in most cases, only as a subtopic under "commands". The easiest way to find the help for commands is through the Contents, under Command Reference.
Simplicity is a good thing, but so is flexibility. The ultimate in simplicity is a generic Telnet client. I'd rather have the scripting power of zMUD even if it is sometimes confusing.
LightBulb
Senior Member |
|
|
|
Troubadour GURU
Joined: 14 Oct 2000 Posts: 556 Location: USA
|
Posted: Wed Jul 17, 2002 5:29 pm |
As mentioned above, you did not read the documentation correctly.
Use the #IF command to decide which command to execute.
#TR {The light turns (%w).} {#IF (%1 = "green") {go} {stop}}
Use the %if function to decide which value to use.
#VAR results %random(1)
#SHOW %if(@results=1,"heads","tails")
Troubadour |
|
|
|
EdwinDroom Wanderer
Joined: 25 Jan 2002 Posts: 77 Location: Ireland
|
Posted: Wed Jul 17, 2002 11:57 pm |
Or use them together
#IF {%if(@results=1,"heads","tails")="heads"} {light=green;go} {light=red;go faster}
:P
As a programmer, I have to say the Zmud documentation (for a one time fee of $25) is at least as accurate and helpful as the documentation for some of the 'top' software I use, at a few hundred or even thousand per upgrade... Play with it and see what it does, as the actress said to the bishop.
All the best freaks are here, please stop staring at me |
|
|
|
|
|
|
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
|
|