0 votes

Whenever I try to update my question label for the quiz I am creating, I keep on getting the error Invalid set index "text" on base null instance with value of type "String", originally I was not getting this error, but as soon as I made the script global I started to get this error, so I don't know if that is what's affecting my program, the code is below

$Question.text = questions[current_question][0]
$Answer1.text = questions[current_question][1]
$Answer2.text = questions[current_question][2]
$Answer3.text = questions[current_question][3]
$Answer4.text = questions[current_question][4]

as for the nodes I have a control node called quiz as the root node, the questions and answers are all direct children of quiz and the script is attached to the quiz node, would appreciate any help

in Engine by (15 points)

1 Answer

0 votes
Best answer

"null instance" is what you get when you give get_node() an invalid path. $Question is no longer a valid path.

Your problem comes from this: "I made the script global". When you set a script as a global, Godot creates a blank node to add it to. That node has no children, therefore all your node references are not valid.

What you should do instead is make the scene, with the question and answer nodes, and the script attached, the global instead.

by (21,981 points)
selected by

It worked! Thanks so much

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.