Error when trying to show a variable

Godot Version

4.6.2

Question

I am trying to randomize an array when i press a button and then show the output, but i get an error when trying to press the button. here is the error: E 0:00:03:378 _process: Error setting property ‘text’ with value of type Nil.
label.gd:11 @ _process()
label.gd:11 @ _process()

label code:

extends Label


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	text = global.mem1

global code:

extends Node

var mem1
var mem2
var mem3
var mem4
var mem5
var mem6
var slot_1_locked = false
var slot_2_locked = false
var slot_3_locked = false
var slot_4_locked = false
var slot_5_locked = false
var slot_6_locked = false
var options: Array = [1, 2, 3, 4]
var Randomizedoptions: Array = [ ]

button code:

extends Button

func _on_pressed() → void:
if global.Randomizedoptions.is_empty():
global.Randomizedoptions = global.options.duplicate()
global.Randomizedoptions.shuffle()
global.mem1 = global.Ranomizedoptions

return global.options.pop_front()

Your code is incorrectly formatted so it’s impossible to see what it says, but the error is because you don’t set the value before the button is pressed so it’s empty

what would i need to set the variable to?

I don’t know it’s your code, some appropriate value for what it is meant to hold

You should also probably not assign the text directly like that, but instead use str(global.mem1)

so i want it to show the output of a randomized array. Sorry if i am making this harder than it needs to be, i am new to godot. Could i need to set it to any text?

Then you should probably just do var mem1 = [] in the file

thank you!

(In the future, please don’t mark your own message as the solution instead of the actual solution, it becomes pretty misleading)

Sorry , i didn’t mean to do that. I misclicked

No worries!