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
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: 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
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Dec 17, 2008 6:44 am   
 
Heh. Not necessarily so. I thought it was ascii values at first, but apparently not. Hmmm...

Charneus
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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