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
seamer
Magician


Joined: 26 Feb 2001
Posts: 358
Location: Australia

PostPosted: Wed Jun 26, 2002 1:58 am   

variable yes and no
 
has anyone come across problems using yes/no inside a variable? i was helping someone make a script where a variable was given a yes or no value, and a trigger that called the variable refused to work until the variable was filled with a different value, in our case we ended up filling it with tellyes or tellno to make the script work.

using 6.16

Why oh WHY did I have pass door on...
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Wed Jul 03, 2002 5:59 pm   
 
If you are trying to use a variable string
with yes or no and make compare with a binary
1/0 Yes/No True/False concept, that probably
wont work.

How about %eval'uating it?

#IF (%eval(@V_My_YesNo_Variable)) {#ECHO y} {#ECHO n}

Does that work?

Ton Diening
Providing untested answers that tend to be
more complicated than others.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Jul 05, 2002 7:20 am   
 
What's the trigger?

LightBulb
Senior Member
Reply with quote
seamer
Magician


Joined: 26 Feb 2001
Posts: 358
Location: Australia

PostPosted: Fri Jul 05, 2002 7:44 am   
 
oo, this thread slipped my radar!

from memory, we were making a setup to send tells from one alt character to another, the alias's were
#alias {tellmeyes} {#var tellme yes}
#alias {tellmeno{ {#var tellme no}
these worked just fine

the trigger went along the lines of
#if {@tellme = no} {#abort 1}
#if {@tellme = yes} {tell X someone sent me a tell!;#abort 1}

yes and no wouldnt be called at all, setup totally unresponsive. the alias writing the variables was changed to write tellmeyes and tellmeno, the trigger was changed to reflect the changes, and then everything worked! wierd...came here to see if there was anything relevant, i tend to break the search engine alot with various searches :)

Why oh WHY did I have pass door on...
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Jul 05, 2002 8:02 am   
 
#IF treats yes and no as logical values, so use the variable directly. This also works for true/false and on/off.
#IF (@tellme) {tell X someone sent me a tell!;#ABORT 1} {#ABORT 1}


LightBulb
Senior Member
Reply with quote
seamer
Magician


Joined: 26 Feb 2001
Posts: 358
Location: Australia

PostPosted: Fri Jul 05, 2002 10:10 am   
 
does this mean the mere existance of a variable defaults as "yes" if no comparison is checked against it?

Why oh WHY did I have pass door on...
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Fri Jul 05, 2002 11:27 am   
 
It's not that the variable defaults to "yes", it's that, like LightBulb said, if the variable contains "yes", it is treated as if it were true, and if it contains "no", it is treated as if it were false. However, if the variable does not exist, trying to expand the variable will return an empty string (""), which is also interpreted as false.

Kjata
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Jul 05, 2002 11:45 am   
 
I spent some time testing this morning, and it appears that there's a bug in 6.16. The results are that 0 and the empty string ("") evaluate as false, anything else (including no, off, and false) evaluates as true.

I usually use 0 and 1 for control variables.

LightBulb
Senior Member
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Fri Jul 05, 2002 1:59 pm   
 
That's because it is not the string "no" or the string "off", but the word no and the word off that must be contained by the variable. A quick test would be:
#IF ("no") {#SH true} {#SH false}
#IF (no) {#SH true} {#SH false}

The first one outputs "true", while the second one outputs "false".

However, the problem lies in that if you store these values in a variable, they become text automatically. Another test would be:
#VAR test "no";#IF (@test) {#SH true} {#SH false}
#VAR test no;#IF (@test) {#SH true} {#SH false}

Now, in both cases, the output is "true".

Maybe it's a bug, maybe not. I've never noticed before since I too use 1's and 0's for these kind of things.

Anyway, the solution should be, as LightBulb suggested, to use 0's and 1's, as these do not suffer from the string conversion, and accomplish exactly the same thing.

Kjata
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