Godot Version
Godot 4.3.stable
Question
G’day!
I’m working on an editor plugin to make developing my game easier/faster, which includes a bunch of custom node types I’ve made with the add_custom_type() method. I only really care about these custom nodes, and different custom nodes will be given to different objects which manage them, so when _handles() is called i quickly check if that node has a script attached to it (as all custom nodes do) and then check of that script resource exists in any dictionaries associated with those different manager objects. here is the code:
func _handles(object: Object) -> bool:
var objScript : Script = object.get_script()
if(objScript != null &&
ChunkRef.has(objScript.get_global_name())
|| ToolRef.has(objScript.get_global_name())):
return true
else:
return false
In theory, if objScript returned null it shouldn’t evaluate those next two conditions, but I select a standard node in the editor (I’m using control nodes in this case) I’m getting the error:
res://addons/my_addon/the_script_im_using.gd:36 - Cannot call method 'get_global_name' on a null value.
And that ‘if’ statement is on line 36, so I’m sure that’s what its referring to. Is the ‘objScript != null’ check incorrect somehow? Or do evaluations not happen in order like this? Most of my programming experience is in C and C++ where an ‘if’ statement won’t evaluate Y after X if X evaluates as false in ‘if(X && Y)’.
This isn’t breaking anything, but I would like to understand exactly what is happening a little better. Any help would br greatly appreciated!