Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Thu Jul 12, 2007 3:06 pm   

[1.34] Expressions using 'or' and data record variables
 
I came across an oddity that I'd like to share and verify with others. Basically, I had a function (expanded variable) that used %if to return 1 or 0 based on certain conditions. I was using %iskey to check for the presence of the keys in my data record variables and decided to try @var.key instead for a little more readability (and less typing in the future). The result was not what I expected and it seems to affect only expressions with several two or more 'or's in them. (Actually, I vaguely recall having a similar problem in zMUD a while back and being told that it's the correct behavior, which I still don't agree with exactly...)

Works:
Code:
#FUNC able_scan {%if(%iskey(@afflictions, asleep) or %iskey(@afflictions, unconscious) or %iskey(@afflictions, stunned) or @paused == 1,  0,  1)}


Doesn't work:
Code:
#FUNC able_scan {%if(@afflictions.asleep or @afflictions.unconscious or @afflictions.stunned or @paused == 1,  0,  1)}


So, is this a bug that will be fixed? Or should I be putting back all my %iskey function calls (which I really would rather not do)?

Thanks.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Jul 12, 2007 5:50 pm   
 
Unfortunately, I can't get this to fail. Looks like you need to give us more information on what these variables contain. Here is my test:

Code:
afflictions.asleep=0
afflictions.unconscious=0
afflictions.stunned=0
paused=0
#SHOW @able_scan()  // displays 1
paused=1
#SHOW @able_scan()  // displays 0
paused=0
afflictions.unconscious=1
#SHOW @able_scan()  // displays 0

This all seems fine. So let us know what data you are using that isn't working.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Thu Jul 12, 2007 6:16 pm   
 
Zugg,

Larkin uses database variables in a rather strange way. He does not leave the Stunned key and set it to 0.
He removes the Stunned key altogether when he is not stunned and adds it and sets it to 1 when he IS stunned.

That said you are not seeing the same results that he is. What he is checking for is not is the value of stunned 0 but instead
he is looking for %iskey(@afflictions, stunned).

He is expecting the fact that when stunned is NOT a key and he checks it and receives a NULL response for the OR to take NULL to mean 0

Edit: Edited to point out that currently the NULL somehow means 1. VERY strange if you ask me.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram

Last edited by Arminas on Thu Jul 12, 2007 6:35 pm; edited 1 time in total
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Thu Jul 12, 2007 6:25 pm   
 
Larkin,

Given the above why not just do this?

Code:
#FUNC able_scan {%if(@afflictions.asleep + @afflictions.unconscious + @afflictions.stunned + @paused > 0,  0,  1)}


The NULL is not counted as a 1 in this case.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Thu Jul 12, 2007 6:47 pm   
 
Arminas is exactly right. I remove the keys when the state doesn't apply (affliction, defense, or whatever I'm tracking). If I have an affliction, the value will usually be 1, though it may be something else (broken_arm = left|right, for example). I don't set them all to 0 because I use #LOOPDB and other things to iterate over all the keys and I need the data record variables to stay as small as possible for efficiency.

So, basically, I expect that @afflictions.stunned returns NULL or "" and this evaluates the same as 0 in an expression with 'or' logical operators, but that's not what happens.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sun Jul 15, 2007 3:09 am   
 
Nevermind. It seems everyone is having trouble with databases.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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