< and > operators not working in jscript

Has anyone encountered this?

For example, if I write:

if (number > 50) {
   ExecuteCode();
}

The contained code always executes, regardless of what the number is.

Conversely, if I write:

if (number < 50) {
   ExecuteCode();
}

The contained code never executes, regardless of what the number is.

Am I using these operators improperly? I hope not, because I’m going to feel really stupid if I am. :sweat_smile:

edit
The “numbers” are legit positive integers, not anything weird.

the operators are right, but I’m pretty sure that your logic has an error, cause there are no such problems

Could you elaborate? Do you mean there are no such logic problems or no such problems with Unity?

edit
Nevermind, I realized that the numbers being tested were not the values that I thought they were, so the operators were behaving as expected. I guess that pinpoints the error in my logic, thanks dreamora.

Kind of reminds me of an issue (bug?) in Flash Actionscript 2 with null operations where if you had:

var myNumber:Number = null;

if (myNumber >= 5)
{
	//always executes, unexpected
}

if (myNumber > 5 || myNumber == 5)
{
	//never executes, expected
}
if (!(myNumber < 5)) 
{
	//always executes, expected
}

I always just concluded that when compiling it converts >= operations into not less-than (and vice versa for <=)

That is interesting. Fortunately, in this case I was simply relying on feedback that showed the original number, but not what the number had become after it had been processed through several operations and then inserted into the if statement. Turns out the processed number was always over 50, hence why the first bit of code always excecuted and the second bit never executed.

I was pretty tired and trying to keep track of way to many things in my head at once. Serves me right for not going to bed when I should have. :roll: