Invalid call on a Scene Node extending Node2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By michaelpbl

I have been trying to solve this for many hours. I have other examples where it works but often I get this error and I can’t for the life of me figure out why.

The script is in a Table Scene which has a Dealer Node. Both nodes are Node2D. The Dealer node is itself a Scene and has a script attached which does contain the freshDeck() function

func _on_FreshDeckButton_pressed():
print("Calling " + str(get_node("Dealer")) + " for a fresh deck")
get_node("Dealer").freshDeck();

This throws the error
Invalid call. Nonexistent function ‘freshDeck’ in base ‘Node2D’

It seems to be saying the Dealer node is a base node (Node2D) and so doesn’t have the function in Dealer. But I have other examples where this works perfectly.
It appears to be random. Sorry, couldn’t upload the image of the project. It kept taking over the whole window

:bust_in_silhouette: Reply From: njamster

Invalid call. Nonexistent function ‘freshDeck’ in base ‘Node2D’

This tells you that the node you’re getting with get_node("Dealer") extends a Node2D. But neither that base-class (Node2D) nor the additions you made to it in the script attached your node include any function called freshDeck. It’s impossible to fix your problem with the information you’ve given - but it’s very unlikely to be “random”. :wink:

I explicitly said the Dealer Node is a scene itself and that the Script associated with it does have a function freshDeck()

That is DealerScript.gd
includes the following lines:

extends Node2D

func freshDeck():
print(“Reached Dealer.freshDeck()”)
get_node(“Deck”).freshDeck()

Which is just a simply relay down to the next level

I have a much simpler example which does the same kind of thing but it DOES work. I’m sure it isn’t random, that I’m missing something crucial, but I can’t see it.

I have a zip file of the project, and images of the engine at the point the call is made, both of which I could post if I were reporting a bug, but I see no way to post them here.

michaelpbl | 2020-04-14 10:36

You can upload your project somewhere else (WeTransfer, EasyUpload.io, whatever, pick your poison ;)) and provide a link to it here.

njamster | 2020-04-14 11:17