If statement error

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By stevepetoskey

so I have this block of code:

if -1 == -1 and array[x][y] > 0:

(The fist statement compares a variable to -1 however the variable should equal -1 and is not the real problem)
it returns an error that states:

Invalid operands 'Array' and 'int' in operator '=='.

I originally thought that the variable that substitutes the first -1 was somehow an array so I replaced it with -1 == -1 and it still gave me this error. Any help would be appreciated.

I’m not sure, but maybe the problem in array[x][comment0-y] > 0. Try to check array[x][comment0-y] type. It must be TYPE_INT to compare with int.

USBashka | 2020-05-02 18:23

yeah the array returns a int value

stevepetoskey | 2020-05-02 18:33

When does this error happen? Is it as you write it, or is it when you run the game? Are you able to reproduce this in a simple test scene?

Zylann | 2020-05-02 18:52

So when I test this in a fresh scene it works fine, and the error happens after I run the game. And it gets weirder, I replaced the array[x][comment3-y] > 0 with 0 > 0 and it still gives the same error, even with out the array in it at all. So I deleted everything and put if 0 == 0 and it worked normally. Now I am really confused.

stevepetoskey | 2020-05-02 19:01

That sounds confusing indeed, but hard to help until you can figure out a way to reproduce this in a simple test project^^"
Maybe the line number Godot reports isn’t the correct one, eventually. Or it says == but maybe the culprit is > due to what’s in your array.

Zylann | 2020-05-02 19:28

There is no way to reproduce this, although I shown a simple if statement (that is for the fact the problem), that statement is in a script which contains 172 lines of code, most of which this single if statement relies on, and those 172 lines of code rely on the 20 different nodes. The only way to reproduce this is by recreating everything, which would defeat the point. Anyways, after more testing I figured out that is works if I change array[x][comment5-y] > 0 to array[x][comment5-y] == 0 but I have no idea why it seems a simple greater than is causing a error which mind you the error says that the equal operator is the problem. This is starting to seem more like a bug on godot’s end, however this exact if statement was working until I added the -1 == -1 part. However I know that is not the problem because removing the array[x][comment5-y] > 0 (which has always been working until now) allows the new statement to work. I don’t know if I explained this correctly but even I have a hard time trying to understand what is going on.

stevepetoskey | 2020-05-02 20:26

If you can’t reproduce this any other way, then your project is then the reproduction project, and should be submitted for a bug I guess… there isn’t much we can do here.

Zylann | 2020-05-02 20:29

ok thank you

stevepetoskey | 2020-05-02 20:31

:bust_in_silhouette: Reply From: stevepetoskey

So I figured it out, the given if statement had a elif statement, that elif statement was causing the error by comparing a array to a integer. I got all mixed up because godot says the problem is the if statement, which is true, but I thought that meant the main if statement, thank you everyone for trying to figure this out, next time I should show more code.