Hi !
I understand that there is no exceptions in gdscript. However, I find myself in an odd situation.
During the processing of my game, I may or may not have created a node at runtime, with the name created_node. Now I want to delete it if it exists.
To find the node, I do a var node_to_delete = get_node("created_node")
. Now, if the node exists, node_to_delete
is now pointing to it, and I can do node_to_delete.free()
or whatever. However, if it does not exists, node_to_delete
now contains null
. So I have to check for that before going further. The final code snippet is thus :
var node_to_delete = get_node( "created_node" )
if node_to_delete == null:
return
else:
node_to_delete.free()
This code runs as intended, however while testing it I noticed an error in the debugger, stating: Node not found: created_node
So, am I writing godotscript the way it was intended? What should I do with that error? Just ignore it? Or should I check that created_node exists before doing my get_node()
? But won't that slow the process down for no good reason?
Please, enlighten me! (and as a bonus, convince me there is a good reason I can't do this with a simple try ... except ...
block :] )