 |
chris-74269 Magician
Joined: 23 Nov 2004 Posts: 364
|
Posted: Wed Dec 17, 2008 5:59 am
[2.37] Bug(?) with if statement involving strings and numbers |
If you attempt to compare a string against a number you will always get a true statement, as in #if (H > 60) {#show true} {#show false}. This came up with me using a script that would capture a variable which was sometimes a number and sometimes a string, so i used a command like
#if ((@testvar > 50) or (@testvar = H)) {do this} {do that}, so whenever it was a string it would automatically evaluate to true unless i do an %int(@testvar) which solves it, I don't know if its just programming practice, but I would think that a string being compared to a number would always default to false |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Wed Dec 17, 2008 6:44 am |
Heh. Not necessarily so. I thought it was ascii values at first, but apparently not. Hmmm...
Charneus |
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Dec 17, 2008 12:15 pm |
It doesn't matter which it returns, really, because either one isn't really right. If you care about the variable sometimes containing a string, check if it contains a number before you start working with it.
|
|
|
 |
|
|