|
Elysiana Newbie
Joined: 24 Mar 2007 Posts: 3
|
Posted: 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? |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: 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! |
|
|
|
Elysiana Newbie
Joined: 24 Mar 2007 Posts: 3
|
Posted: 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?
|
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: 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 |
|
|
|
Elysiana Newbie
Joined: 24 Mar 2007 Posts: 3
|
Posted: Sun Mar 25, 2007 12:44 am |
Ahh, I misread it the first time. That does work, thank you muchly!
|
|
|
|
|
|