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
Elysiana
Newbie


Joined: 24 Mar 2007
Posts: 3

PostPosted: Sat Mar 24, 2007 10:48 pm   

Value comparison troubles
 
I'm having some trouble with comparing values in cmud. I'm actually seeing this in two places in my scripts currently; the one that I've seen longer is relatively minor and just annoying, but the newer one is a significantly more problematic case.

The original script where I saw this problem:
Code:
#LOOPDB @herbgoals {
   $totalcount = @RiftCount.%key + @BeltCount.%key
   #IF ($totalcount < %val) {
      #IF ($totalcount < %eval({ %val / 2})) {
         #say *%key %eval({%val - @RiftCount.%key - @BeltCount.%key})
      } {
         #say %key %eval({%val - (@RiftCount.%key + @BeltCount.%key)})
      }
   } {
      #say Have $totalcount, want %val of %key
   }
}

With this script, I have the two variables, RiftCount and BeltCount, and they have all the relevant keys with integer values. Typical output includes:
Quote:
wormwood 34
Have 956, want 1000 of yarrow

Out of approximately 20 entries, about four or five never compare correctly - and it's consistently the same four or five. I've tried re-entering the numbers to make sure there's no hidden spaces or anything, but I've so far had no luck with that.

My recent attempt where I encountered a related issue is comparing a set of status values:
Code:
#if (@hp == @maxhp and @mana == @maxmana and @ego == @maxego) {do stuff}

Looking at it more closely, all three pairs of integers match, but the third pair does not evaluate to being equal. I tried:
Code:
#say Ego: @ego Max ego: @maxego   Equality: %if(@ego == @maxego, True, False)

and got:
Quote:
Ego: 5647 Max ego: 5647 Equality: False


Is there something I'm missing to make these comparisons more reliable?
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sat Mar 24, 2007 10:56 pm   
 
One of the variables may be getting treated as a string. This is a known bug. One solution to explicitly cast the variable as a certain type.


Code:
#say Ego: @ego Max ego: @maxego   Equality: %if(%int(@ego) == %int(@maxego), True, False)


Try that and see if it helps.
_________________
Asati di tempari!
Reply with quote
Elysiana
Newbie


Joined: 24 Mar 2007
Posts: 3

PostPosted: Sat Mar 24, 2007 11:03 pm   
 
Ahh, thank you, that did help with the second case. Is there a way to set the type of values in a database variable, though, or is that problem likely to be related to something else?
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sun Mar 25, 2007 12:35 am   
 
Same sort of thing should work with the database variables. %int(@BeltCount.%key)
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Elysiana
Newbie


Joined: 24 Mar 2007
Posts: 3

PostPosted: Sun Mar 25, 2007 12:44 am   
 
Ahh, I misread it the first time. That does work, thank you muchly!
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