Godot Version
4.3
Question
In a nutshell, I want the player to send a signal to all my chests in the game passing a chest ID. Each chest will compare the ID to its own (variable) and if it’s a match, the status of the chest will change.
I’m using this approach because I have multiple chests and multiple keys. The correct key/chest combinations are not determined until runtime using a global script that loads everything.
I have placed all my chests in a group chests. This is just a small sample, the finished game will have more chests and keys.
In my player script, I’m trying to setup up the signal that is sent to the chests.
I’m in the player script, so I’m using a straight connect without identifying the source node.
connect(signal_name, recieving node.function)
signal open_door_chest
var chestItems
func _ready() -> void:
set_process(true)
chestItems = get_tree().get_nodes_in_group("chests")
connect_chest_signals()
#
func connect_chest_signals():
for chest in chestItems:
connect("open_door_chest", chestItems[chest]._opening_chest)
I also tried…
connect("open_door_chest", chestItems[chest]."_opening_chest")
and…
connect("open_door_chest", chestItems[chest]"_opening_chest")
My error is:
Invalid access to property or key 'Chest1:<StaticBody2D#30098326799>' on a base object of type 'Array[Node]'.
Please enlighten this humble noob.
Thank you in advance.