"" not equal Zero

Archives Forums/Blitz3D Bug Reports/"" not equal Zero

jfk EO-11110(Posted 2007) [#1]
There's a little bug in the internal autocast when used in a IF condition.

I got a function "GetParameter()" in my program. It will search for a substring inside an other string and it tries to extract the parameter that follows the substring, eg:
c$ = "object:123 height:55.4"

;and it's used this way:
Print GetParameter(c$,"height:")
;--------

Function GetParameter$(cmd$,sub$)
 if the substring can't be found at all, then return right here:
  Return ""
 endif
 ;... extract and return parameter of "height:"
 return param$
end function

Return Type must be string, cause it's a generic function that allows to return any parameter.

Now here's the problem: using this

If GetParameter(c$,"height:")<>0
 myvar#=GetParameter(c$,"height:")
else
 myvar#=0
endif


Where the if line says it is not zero, myvar will read it as zero. This will of course result in hard to find bugs, eg. when used as an optional ScaleTexture parameter.

Although, it's easy to prevent these troubles when you use the IF statement like this instead:

If Float(GetParameter(c$,"height:"))<>0


Floyd(Posted 2007) [#2]
The Expressions page of the Language Reference explains how the autocasting works.

You are in effect comparing strings and the integer 0 gets cast to "0".


jfk EO-11110(Posted 2007) [#3]
I was assuming when I compare a string to a float it will be autocasted to float before it actually compares things. It isn't a real bug, just a source for code problems. That said, a function that has to return all types of parameters as a string, including numbers, isn't required often.