+3 votes

Hi, I'm having a very annoying problem that I just can't seem to figure out.

I am trying to access a function in the script of a child using this line:

var save_info = get_node("World").save()

This line gives me the error: "Invalid call. Nonexistent function 'save' in base 'Node'."

This is my node structure:
Game (game.gd)
|_ World (world.gd)

My world.gd script:

class_name GameWorld
extends Node

func save():
    var something = value
    return something

Does anyone know what's going wrong here?

Thanks in advance.

in Engine by (15 points)

Also: Instead of get_node("World"),save() can use $World.save()

or even better save world so can use it any time without doing a costly get_node

onready var _world := $World

2 Answers

0 votes

Make class_name same as script name i think:

classname World or GameWorld.gd

Might have to close and reopen after changing.

by (1,667 points)
0 votes

Looks fine, the problem is probably something else. Try putting a breakpoint on the line var save_info = get_node("World").save() and then checking the remote tab in your editor to validate that you do have a "World" node with the script attached: https://docs.godotengine.org/en/stable/tutorials/debug/overview_of_debugging_tools.html#remote-in-scene-dock

Could you share more? The complete scripts of Game.gd and World.gd, as well as a screenshot of your scene tree?

by (1,100 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.