0 votes

So, I am making a basic typing game.
My current main script creates an instance of a letters scene for use in the main scene.
I need to keep track of the random letter or word generated for removal on user inputs.

My primary question is how you go about accessing members of an instanced class.
Currently:

func _on_WordsTimer_timeout():
$WordsPath/WordSpawnLocation.set_offset(randi())
words = Words.instance()
add_child(words)
print($words.letter)
words.position = $WordsPath/WordSpawnLocation.position

The print statement is my primary point of questioning here.
On running my project with no print statement characters spawn as expected.
With the print statement however I am getting
Invalid get index 'letter' (on base: 'null instance')

How should I go about accessing member variables of an instanced child node for usage in the main or other scripts?

in Engine by (18 points)

1 Answer

+2 votes
Best answer

words is the variable you assigned the instance to, so you wouldn't put a $ in front of it.

print(words.letter)
by (21,920 points)
selected by
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 Frequently asked questions and 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 [email protected] with your username.