Author Topic: [SOLVED] Weird result from if statement  (Read 915 times)

So I have value %closeEnough defined by
Code: [Select]
%closeEnough = %xFinal - %yFinal;
echo("Close enough value:" SPC %closeEnough);

Then later on I have
Code: [Select]
if(0.05 > %closeEnough > -0.05){
   echo("DEBUG: Results come from close enough statement");
   //other stuff
}

But then I am (very annoyingly) seeing
Code: [Select]
Close enough value: 0.2
DEBUG: Final result is coming from the CLOSE ENOUGH statement

There's nothing wrong with the xFinal and yFinal values as I've checked those. Anyone any ideas? :(

I've also tried
Code: [Select]
if(%closeEnough < 0.1 && %closeEnough < -0.1)
It makes no sense to me
« Last Edit: February 22, 2016, 01:48:42 PM by Jervan »

you can't do this
Code: [Select]
if(0.05 > %closeEnough > -0.05){
   echo("DEBUG: Results come from close enough statement");
   //other stuff
}
this is how you would achieve what you want
Code: [Select]
if(%closeEnough > -0.05 && %closeEnough < 0.05)
{
   echo("DEBUG: Results come from close enough statement");
   //other stuff
}
There's nothing wrong with the xFinal and yFinal values as I've checked those. Anyone any ideas? :(
I've also tried
Code: [Select]
if(%closeEnough < 0.1 && %closeEnough < -0.1)It makes no sense to me
this is checking if closeEnough is less than 0.1 and then also checking if closeEnough is less than -0.1

The second statement doesn't get interpreted as you'd expect.
First it decides 0.05 is not larger than close enough, then it decides the 0 that gets returned is larger than -0.05 returning 1 thus reaching inside the if statement.
Edit: God damn it Swollow.

Yeah, like the above poster said, you were first trying to format an if statement incorrectly and then your second if statement's logic was flawed.


Hmm still getting the error with the new if statement.
It says in console closeEnough is -0.14 but the parameters are closeEnough > -0.1 && closeEnough < 0.1 yet it still enters the statement :S

EDIT: I'm gonna try squaring the value and just working with positive numbers
EDIT2: Found a similar error, thanks again
« Last Edit: February 22, 2016, 01:48:30 PM by Jervan »

If I remember torkscript has issues with floats in if statements

If I remember torkscript has issues with floats in if statements
it doesn't have any notable issues that every other coding language don't have with floats

Wasn't there a topic about it?

Wasn't there a topic about it?
torquescript works reasonably fine if you dont try to do crazy things, its irrelevant because the issue here was the way Jervan was doing the if statements and how they evaluated, not an issue of floats