I have main script attached to the root node Inv_UI
of the scene. In this script I have an array that consist of 2 other arrays and is prefixed with @onready
. My original goal that I still want to achieve is to be able to access this declared variable slots
from another scene and since I really do not want to do it through instancing the whole Inv_UI
scene I tried to do it with an autoloader but that broke something and caused an error that I believe would force me to not use the @onready
prefix which is needed. That is why I thought I could add a node with a script that would get the slots
variable with a signal that is emitted at the time when slots
has all the necessary values and then use that as an Autoloader
but I am very new to godot and cant seem to understand how to make the signals work.
Here is the code of the root node Inv_UI
:
extends Control
@onready var slots: Array =$Hotbar/GridContainer.get_children() + $Inventory/GridContainer.get_children()
signal SlotsReady (slots: Array)
func _ready():
emit_signal("SlotsReady", slots)
And heres the code for the listening script which I plan to use as an autoloader for slots
:
extends Node
@onready var SlotsArrayNode = $".."
func _ready():
SlotsArrayNode.connect("SlotsReady", self, "_on_slots_ready")
func _on_slots_ready(slots: Array):
print(slots)