Invalid operands 'Object' and 'bool' in operator '=='

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By xFrenchy
var result : bool = Globals.fight(room_node)
	if  result == true:

It’s breaking at the if statement thinking that result is an object instead of a boolean. I don’t understand how this error is happening since I made result to be of type boolean. fight function is a boolean function as well

func fight(monster) -> bool:

So the function returns a boolean in every path, (has too or else gdscript yells at you), and a variable of type boolean stores it’s result. How is it confusing result as an object? I originally had this as just one line but decided to separate it to see if anything would change. I don’t exactly need this to be fixed, I can do a different check, I just find it odd that what seems to be a guaranteed boolean, is being treated as an object

Not sure how to solve your problem, but why even check against true?
A boolean can just be checked with the if statement:

if result:

is the same as:

if result == true:

And an Object, if you are just checking if it exists or is null, basically a null check you can do the same:

if object:

is the same as:

if object != null

tastyshrimp | 2020-01-09 22:32

It’s for my readability sake and preference, that’s all. The way I think is “if this is true, then do that” not “if this, than that”

xFrenchy | 2020-01-09 23:55