|
Zafrusteria Wanderer
Joined: 11 Oct 2000 Posts: 94 Location: United Kingdom
|
Posted: Mon Sep 01, 2003 6:42 pm
#IF then else maybe? |
#SHOW test is running
#VARIABLE temp "Green"
#IF (@temp=~"Green") {#SHOW "true Green=Green"} {#SHOW "False Green<>Green"}
Can you guess what this will print on your screen after the line "test is running"?
The answer is it prints nothing! We do not go through the true or false part.
This was done on a new char so there were no other alias' to get it messed up.
Anyone any ideas why this fails to display anything?
Zaf |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Sep 01, 2003 7:01 pm |
Yes. Since you have ~", zMUD treats the " as a normal character. It then encounters "), which tells it to treat the ) as part of the string being tested. It never encounters another " to terminate the string and it never encounters another ) to terminate the condition.
Learn to use spaces.
Any of these will work:
#SHOW test is running
#VARIABLE temp "Green"
#IF (@temp =~ "Green") {#SHOW "1. true Green=Green"} {#SHOW "1. False Green<>Green"}
#IF (@temp=~ "Green") {#SHOW "2. true Green=Green"} {#SHOW "2. False Green<>Green"}
#IF (@temp = "Green") {#SHOW "3. true Green=Green"} {#SHOW "3. False Green<>Green"}
#IF (@temp="Green") {#SHOW "4. true Green=Green"} {#SHOW "4. False Green<>Green"}
#IF (@temp=~"Green"") {#SHOW "5. true Green=Green"} {#SHOW "5. False Green<>Green"} |
|
|
|
Zafrusteria Wanderer
Joined: 11 Oct 2000 Posts: 94 Location: United Kingdom
|
Posted: Mon Sep 01, 2003 8:51 pm |
Ok thanks for the tip on spaces. Zmud has weird syntax with spaces though, not like most other scripting languages. Sometime you get unxepected results when you have spaces.
So why does @obj not get set, when I use: test Green
#SHOW test is running
#VARIABLE temp "Green"
#IF (@temp =~ "Green") {
#SHOW "1. true Green=Green"
#VARIABLE @obj something
} {#SHOW "1. False Green<>Green"}
#SHOW @obj
If prints "1. true Green=Green" so why not execute the rest of the commands? |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Sep 01, 2003 10:57 pm |
#VARIABLE accepts indirect addressing.
#VAR obj test1
#SHOW test is running
#VARIABLE temp "Green"
#IF (@temp =~ "Green") {
#SHOW "1. true Green=Green"
#VARIABLE @obj something
} {#SHOW "1. False Green<>Green"}
#SHOW {~@temp is @temp, ~@obj is @obj, ~@@obj is @{@obj}} |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue Sep 02, 2003 2:10 am |
In other word you probably want to use:
#VAR obj something |
|
|
|
|
|