wtf am i doing wrong... ERROR

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

@onready var label1 = $storyText

func _ready():
	# Generate a random name and backstory for the player
	var name1 = BioGenerator.NAMES[randi() % BioGenerator.NAMES.size()]
	var backstory = BioGenerator.BACKSTORIES[randi() % BioGenerator.BACKSTORIES.size()].replace("{name}", name1)

	# Set the labels to display the name and backstory
	label1.text = "Name: " + str(name1)
	label1.text = "Backstory: " + str(backstory)

#ERROR  invalid set index 'text' (on base: 'null instance') with value type of 'String'

it uses a autoload dictionary for the random gen. if you want to see that to i’ll post it but i think the error has nothing to do with that script.

CluelessCoder | 2023-05-04 21:55

Edited to fix forum code formatting…

jgodfrey | 2023-05-05 00:22

:bust_in_silhouette: Reply From: jgodfrey

The error is saying that your label1 variable is null. So that means that this line isn’t working as intended:

@onready var label1 = $storyText

So, you must not have a node named storyText that’s an immediate child of the node associated with the posted script (it could be the character case of the node name)…

Yes that was correct. I fixed it by attaching the script to the first node in the scene and the label was a child of that node so it worked.

CluelessCoder | 2023-05-05 19:14