Godot Version
4.3 stable
Godot is trying to call a function, even though an export node2D and Bool are both set to null/false.
> if sword and swordBool:
sword._level_1()
else:
print("sword absent")
#elif sword == null:
#pass
if bowBool == true:
bow._level_1()
I expected with the export node empty, and the bool set to false, Godot would run the else, and then move on to the “if bowBool” command, but I keep getting “Invalid call. Nonexistent function ‘_level_1’ in base ‘Node2D’.”
What can I do to stop the code from trying to call the function?
Does it show the error for sword._level_1(), or for bow._level_1()? You don’t check for the bow node. Also, does the function _level_1() exist in both nodes?
It’s always showing the error “Invalid call. Nonexistent function ‘_level_1’ in base ‘Node2D’.” and directing to the sword reference (sword._level_1)
Both nodes have a function “_level_1()”
Surely if “sword” and “swordBool” are both false, Godot shouldn’t be trying to call “sword._level_1()”?
When I comment out “sword._level_1()” and replace with a pass, the code runs fine:
There’s no error for calling “bow._level_1()”
is this sword Node error happened when you create the scene with it in it? or after a while of playing, whenever try to access sword’s node function, it doesnt work? are you sure you have attached the sword’s script to the sword scene’s root node? have you saved the scene before press f6/play by scene?
Basically, it’s part of a skill tree system that should be checking if the player has a bow, a sword, or possibly both
So, in this case the player does not have a sword, and so the sword scene is absent
Hence the bool to check if the sword is present.
I assumed that if the sword is null, making the bool null, the if statement would pass over the call
“Is the sword here? if no, sword bool is false. If sword bool is not false, call sword _level_1. Else, call bow _level_1”
Something along those lines as typed in psuedocode
For now I’ve made a (temporary) fix to call a dummy node in place of the sword when the player doesn’t have one.
But I’m still quite interested why Godot doesn’t seem to be listening to my bool check
Did you try setting a breakpoint at sword._level_1() and examining the values? Godot does not ignore bool checks, so the error must be in your code/scene
I don’t think its from the boolean checks, they look right, but just in case - did you try with more explicit bool checks (e.g. sword != null
) or even nested checks?
It might be good if you post the code where you initialize the sword and swordBool variables.
Also, just to make sure, you’re not using the elif sword == null
after an else
case, right?
I agree, this would be a good starting point to find the error