0 votes

(Sorry in advance if some of my terminology is weird/wrong. I'm self-taught. lol)

I had been working on this project for a while and everything was running relatively smoothly. I created a little script for running cutscenes in my game using sprites nested in a Node2D.
However... I'd been having trouble with Java on my computer, so when an update came out, I jumped on it, and when I booted up godot, the next time, my project gave me an error every time I tried to build it (i think the project file itself became corrupted), but the assets remained unchanged, so I decided to simply transfer them (the art, scenes, and scripts) to a new project.

Basically everything else works the same except for the script that handles the cutscenes, and I have no idea why.

There are a lot of objects that I reference through variables in this script, and it seems that when I use the variables to reference them, it no longer works. I have to use the $[relative_path] every time I need to do something and... frankly, it's a pain.

The gist of it is that I have several sprites packed as scenes that I load dynamically into the cutscene. I load them all into a node2D called "ToyBox" that I can use to do simple animations (moving the whole stage at once, shaking the sprites, etc).

onready var toybox = get_node("ToyBox")

func load_toy(sprite:String): #loads a sprite using an absolute filepath
    var ts = load(sprite)
    var talksprite = ts.instance()
    toybox.add_child(talksprite)
    return talksprite #returns it so I can pass it to another variable elsewhere

Basically, it's supposed to load a sprite, instance it, and make it a child of the toybox. However, when I run this code, it gives me the error "Invalid call. Nonexistent function 'add_child' in base 'NIL'."
I don't know if I'm just passing the object to the variable incorrectly or what, but I've also tried doing it in the _ready function to the same result:

var toybox

func _ready():
    toybox = get_node("ToyBox")

loadtoy() only works for me if i change "toybox.addchild()" to "$ToyBox.add_child()" (and it's the same for the other nodes that I reference through variables as well).
When I run:

print(toybox,$ToyBox)

it returns the same object id tag for both:

[Node2D:1314][Node2D:1314]

so I think it must be set up correctly...

The only thing I can think of is that it's running the code before it loads properly, so before the variable is set, but even when I change it to $ToyBox, there's another similar piece of code that runs later in the scene (like, many seconds later) that gives me the same error.

Also, all of this was working properly (as far as I could tell) before I moved this stuff to the new project...

I'm using Godot 3.2.1 on windows10.

Godot version 3.2.1
in Engine by (12 points)

I think you should add some breakpoints and check the debugger to see the exact values of the variables. Could help.

Ah, thanks for suggesting. It hasn't solved my problem, but I'd been avoiding actually figuring out how the debugger works until now, so this will probably make my life at least a little bit easier.

Please log in or register to answer this question.

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.