Giving each instance a different value for a variable

Godot Version



I’m a bit new to godot, and I was trying to experiment with UI, basically I have a scene that is a grid of 8 buttons, each button is also a scene consisting of a panel container and a button. What I want to do is on creation give each button it’s own unique number so that I can use one script to send it to the main script that will then be able to analyze which button was pressed and respond accordingly.

Currently I have this in the button code:

extends Control
@onready var button_node = get_node(“ButtonPresser”)

func _ready() → void:
button_node.text = name

func _on_button_presser_pressed() → void:
print(button_node.text) # Replace with function body.

I can use the @onready to create a variable but it’s the same across all the instances of the buttons. So how do I make a variable that’s different for each one?
Also, again, I’m fairly new, so if I’m doing this completely backwards then it would be helpful to know the right way to do things as well.

@export var number = 5
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.