Why does this "if" statement not execute correctly? (see pic)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By thatsalottadimp
:warning: Old Version Published before Godot 3 was released.

Here is a pic of my problem while I’m debugging:

So in line 10, I check the tileLoc variable which is 0 as you can see at the bottom, but my code is skipping to line 16 instead of executing line 11-13. Am I having some sort of brain fart here and missing something simple?

Thanks in advance for any help.

:bust_in_silhouette: Reply From: volzhs

get_translation().x is float value and comparing equality float value is not good idea.
It’s better to compare range or distance, like if abs(get_translation().x) < 0.001

I’ll give it a try a little later. Thanks!

thatsalottadimp | 2017-01-12 16:50

changing it to tileLoc > -0.1 did the trick. Thanks!

thatsalottadimp | 2017-01-13 01:33

:bust_in_silhouette: Reply From: MrMonk

not sure if this is your problem, but it seems the error shown is one line below than what it should show, so your error might actually be at the else: line which is actually at the if line… This is a problem with the editor, and I saw this in every error I get.: errors are above the line indicated by debugger.
To test this further put something ,( a print line )inside the else function and see if it gets printed.

There’s no error message, that’s just telling me where my current step in the debugging process is. I think it’s a float problem that the other 2 answers are talking about.

thatsalottadimp | 2017-01-12 16:49

:bust_in_silhouette: Reply From: ingo_nikot

float precision problem is assume:


var a = 0.00000000000000001
if (a == 0):#debugger will say a is 0, but its not
	#will not fire

so use distance like volzhs suggested