Is this expected behavior ?
enum TYPE_ {nav, pu, drop, ap}
export(TYPE_) var type
func on_hs_click():
if type==TYPE_.nav: #ERR
pass
ERR : Invalid operands 'String' and 'int' in operator '=='
Is this expected behavior ?
enum TYPE_ {nav, pu, drop, ap}
export(TYPE_) var type
func on_hs_click():
if type==TYPE_.nav: #ERR
pass
ERR : Invalid operands 'String' and 'int' in operator '=='
You probably assigned a string to type somewhere else in the code.
As xyz said, you assigned type variable with String. Modified example to show what's going on:
extends Node2D
enum Type {NAV, PU, DROP, AP}
export(Type) var type
# Uncomment to throw error
#func _ready():
# type = "Throw error"
func on_hs_click():
print(type)
if type == Type.NAV:
print("No error")
func _input(event: InputEvent) -> void:
if event is InputEventKey:
on_hs_click()
Finally figured it out ... I used to have 'type' defined as a String. Yesterday, I changed it into an enum. There seems to be some sort of caching issue that even an editor restart doesn't solve. I needed to change the value assigned to the export variable (in the property inspector), and only then did Godot update from string to int ... :/
Thank you both for your quick replies !