Okay, what in the holy guacamole am I doing wrong. I have two scenes for my game. One scene updates the index of the saved pet when the UI arrows are pressed. Looks like this:
#GlobalSignalBus.gd
extends Node
signal selected_Pet_Index_Changed(index: int)
And then I have another scene that should be listening to the input from the first and change accordingly.
extends Control
@onready var petNameLabel2 = $MainInfoPetName
@onready var petBirthdayLabel2 = $MainInfoPetBirthday
var selectedPetIndex: int = 0 # Declaration of selectedPetIndex
func _ready():
GlobalSignalBus.selected_Pet_Index_Changed.connect(_on_selected_pet_index_changed)
func _on_selected_pet_index_changed(index: int):
print("Selected pet index changed to:", index) # Debugging print statement
selectedPetIndex = index
updatePetLabels(selectedPetIndex)
func updatePetLabels(index: int):
print("Updating pet labels for index:", index) # Debugging print statement
var pet = PetStorage.get_pet(index)
if pet != null:
petNameLabel2.text = pet.name
petBirthdayLabel2.text = pet.birthday
petNameLabel2.visible = true
petBirthdayLabel2.visible = true
else:
petNameLabel2.text = "no index"
petBirthdayLabel2.text = "no index"
petNameLabel2.visible = false
petBirthdayLabel2.visible = false
Now, first of all, I’m getting an error and have no idea why:
res://main/Resources/main_middle_section.gd:19 - Compile Error: Identifier not found: GlobalSignalBus
Second of all the script that should be receiving the information from the signal is not doing so, because the labels don’t display anything, neither does anything get printed in my desperate attempt to debug the thing.
I think the issue is you need to emit the signal from the globalsignalbus autoload script.
I was trying to do something similar in C# and came up with this problem.
So you would create a function in the globalbus script that emits the signal and then from the first script call that function instead. Which even if it isnt necassarry is better OOD design as the globalbus is doing the work.
You could try removing GlobalSignalBus from autoloads in ProjectSettings and adding it again. I’ve had some weird issues with autoloads that I was able to fix by doing that.
It should work without all that though. I have a global signal bus and I emit signals like this:
Unfortunately, I can’t think of anything else that could help. There is one (already closed, so it should be fixed) issue with similar error message but it’s related to tool scripts (Edit: and it’s very old issue anyway, didn’t check the date)
Alright, managed to figure it out thanks to an awesome person in one of the Discord communities. If anyone stumbles upon this post in the future - make sure that your script is actually attached to the tree. My scene was being accessed through StageSwitch.goto_scene(“res://Info/info.tscn”) instead of being directly in the tree. Putting it into the “main” scene resolved all issues.