Scryth2004-12-17 17:00:09
A pair of questions:
1. What do %pop() and %item() return if there is no items in the list? %null? 0? Something else?
2. What is wrong with this:
#alias autostand {
#if (%1="on") {
autostand=1
#echo Autostanding ENABLED
}
#if (%1="off") {
autostand=0
#echo Autostanding DISABLED
}
#if (@autostand=1) {#echo Autostanding is ENABLED} {#echo Autostanding is DISABLED}
}
What I am trying to accomplish is: "autostand on" sets autostand to 1, "autostand off" to 0, "autostand" tells if it's 0 or 1. However above script doesn't seem to work. What am I doing wrong?
1. What do %pop() and %item() return if there is no items in the list? %null? 0? Something else?
2. What is wrong with this:
#alias autostand {
#if (%1="on") {
autostand=1
#echo Autostanding ENABLED
}
#if (%1="off") {
autostand=0
#echo Autostanding DISABLED
}
#if (@autostand=1) {#echo Autostanding is ENABLED} {#echo Autostanding is DISABLED}
}
What I am trying to accomplish is: "autostand on" sets autostand to 1, "autostand off" to 0, "autostand" tells if it's 0 or 1. However above script doesn't seem to work. What am I doing wrong?
Kaelar2004-12-17 17:33:53
#2
I tried to do the same thing with my Autosipper, and couldn't get it to work. In the end, I just decided to change it to an alias that toggled it on and off. If the variable was 1, it would set it to 0 and echo that it had been disabled; if it was 0, it would set it to 1 and echo that it had been enabled.
Not sure if thats how you want it in your case, but it works
I tried to do the same thing with my Autosipper, and couldn't get it to work. In the end, I just decided to change it to an alias that toggled it on and off. If the variable was 1, it would set it to 0 and echo that it had been disabled; if it was 0, it would set it to 1 and echo that it had been enabled.
Not sure if thats how you want it in your case, but it works

Sudoxe2004-12-17 17:39:24
Put each of the %1's in quotes.
If ("%1"="on") ...
If ("%1"="on") ...
Unknown2004-12-17 19:44:21
The answer to your first question is that %pop and %item will return a value equivalent to %null when your list is empty. I tested this myself, so I can guarantee that it's true. 
For your second question, Sudoxe has it right. zMUD considers the quotes to be part of the expression and includes them in the matching. Use quotes around both sides or neither side. (When matching against more than one word, you need the quotes on both sides.)

For your second question, Sudoxe has it right. zMUD considers the quotes to be part of the expression and includes them in the matching. Use quotes around both sides or neither side. (When matching against more than one word, you need the quotes on both sides.)
Scryth2004-12-17 22:56:41
QUOTE(Zarquan @ Dec 17 2004, 10:44 PM)
The answer to your first question is that %pop and %item will return a value equivalent to %null when your list is empty.
18612
So construction like #if (%pop(afflictions)=%null) {#dontcureanything} should work?
Unknown2004-12-17 23:16:38
In theory, that will work just fine, yes. Here's what I did for my little test:
CODE
#additem TestVar hello
#additem TestVar bye
#loop 3 {#if (%pop(TestVar) = %null) {#show Nothing left to pop} {#show Popped one off}}
#additem TestVar bye
#loop 3 {#if (%pop(TestVar) = %null) {#show Nothing left to pop} {#show Popped one off}}
Shihsou2004-12-29 00:40:05
Yeah, that should work with the quotes, though you might try something like this instead.
#ALIAS {stand} {
#IF ("%1" != "%null") {
#IF ("%1" = "on") {
#T+ "autostanding"
#ECHO ***Autostand ENABLED!***}
#IF ("%1" = "off") {
#T- "autostanding"
#ECHO ***Autostand DISABLED!***}
} {
stand}}
That way "stand" will stand, "stand on" will turn your autostand trigger on, and "stand off" will turn it off. You'll find that its always best to use aliases over triggers, as far as speed is concerned.
CODE
#ALIAS {stand} {
#IF ("%1" != "%null") {
#IF ("%1" = "on") {
#T+ "autostanding"
#ECHO ***Autostand ENABLED!***}
#IF ("%1" = "off") {
#T- "autostanding"
#ECHO ***Autostand DISABLED!***}
} {
stand}}
That way "stand" will stand, "stand on" will turn your autostand trigger on, and "stand off" will turn it off. You'll find that its always best to use aliases over triggers, as far as speed is concerned.
Unknown2005-01-03 08:54:14
The problem with Scryth's script is that it missed out some "{"s and "}"s, and any quotes around the %1 shouldn't have any effect in this as it can be only a single word. Also, you should use #VAR for changing the value of variables instead of doing var=x, as the latter sometimes creates multiple copies of a variable with the same name, which will ruin some scripts. Also, you don't need to do @Autostand=1 in #IFs, as @Autostand is the same thing.
CODE
#alias autostand {
#if (%1="on") {
 #VAR Autostand 1
 #echo Autostanding ENABLED
 } {
#if (%1="off") {
 #VAR Autostand 0
 #echo Autostanding DISABLED
 } {
#if (@Autostand) {#echo Autostanding is ENABLED} {#echo Autostanding is DISABLED}
}
}
}
#if (%1="on") {
 #VAR Autostand 1
 #echo Autostanding ENABLED
 } {
#if (%1="off") {
 #VAR Autostand 0
 #echo Autostanding DISABLED
 } {
#if (@Autostand) {#echo Autostanding is ENABLED} {#echo Autostanding is DISABLED}
}
}
}
Unknown2005-01-03 12:48:10
QUOTE(Zaltan @ Jan 3 2005, 04:54 AM)
Also, you don't need to do @Autostand=1 in #IFs, as @Autostand is the same thing.
Not entirely true. The #IF command will evaluate to true on any non-zero, non-null value. If you set Autostand to "blah," the statement #IF (@Autostand = 1) will be false and #IF (@Autostand) will be true. In the case of Scryth's script, yes, they are equivalent. In other scripts, however, you may have good reason for checking specific values. (There's also an oddity or two in the way zMUD evaluates lengthy expressions, especially with null variables and the 'or' logical operator.)
Unknown2005-01-04 05:09:55
QUOTE(Zarquan @ Jan 4 2005, 01:48 AM)
Not entirely true. The #IF command will evaluate to true on any non-zero, non-null value. If you set Autostand to "blah," the statement #IF (@Autostand = 1) will be false and #IF (@Autostand) will be true. In the case of Scryth's script, yes, they are equivalent. In other scripts, however, you may have good reason for checking specific values. (There's also an oddity or two in the way zMUD evaluates lengthy expressions, especially with null variables and the 'or' logical operator.)
24531
Yeah, well, I meant in that script.