Hi, do you know any reason why in gdscript is does not behave like ==?
extends Node
enum STATE{ON,OFF}
var state:STATE=STATE.OFF
func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
print("this works")
if event == InputEventMouseMotion:
print("this doesnt")
if state is STATE.OFF:
print("this doesnt")
if state == STATE.OFF:
print("this works")
is will check if the object is of a given type (can be extending a type or being a type). == will compare the variable values, not their type.
Here, event is âof typeâ InputEventMouseMotion, but âis not equalâ to the InputEventMouseMotion type, and state value âis equal toâ STATE.OFF but is not âof typeâ STATE.OFF.
Not really sure what if state is STATE.OFF actually does as STATE.OFF is an enum value, which is not reaaaally a type, but you always want to check for enum equality using == anyway.
That would defeat the purpose of is and would make a lot of polymorphic operations a LOT more difficult to achieve, if not impossile. Sometimes you have to check if something is a specific type, and not just value. It would make no sense if == behaved exactly like is, and I do hope itâll never happen. I suggest you read up on Object oriented programming, and youâll see a lot of examples of why making them both behave the same way would be a bad idea.
Iâm used to do my own type checking, void * is my friend, letâs me do whatever I want in C(++). Using enums is way faster than typechecking, and since I banged my head on walls for a morning trying to make a complex set of code working that hit the is is not == wall. If all derived objects had an enum instead of global lookupsâŚ
Thanks for all your comments, now is/== is burned in my brain, and hopefully not too many more walls to tear down ahead. Cheers