That's a good question. I'm relatively new to Godot myself but I've got some experience working with Unity3D.
What signal do you want to connect? Is the node that emits the signal instanced during runtime?
If so, you could provide a function within your Singleton to connect to the signal.
Let's say you want to connect your global listener to the same "rolled" signal of your dice scene:
Add the globallistener.gd script to the AutoLoad list within the project settings and name it "globallistener" or something similar (I'll stick with globallistener).
dice.gd
signal rolled
func _on_dice_clicked():
var rolled_number = 123
emit_signal("rolled", rolled_number)
gameboard.gd
var global_listener = get_node("/root/globallistener")
var new_dice = dice_scene.instance()
#add_child and position your stuff here
new_dice .connect("rolled", self, "_on_dice_rolled")
global_listener.connect_dice(new_dice, "rolled")
func _on_dice_rolled(argument):
#do stuff to update your value
globallistener.gd
func connect_dice(instanced_dice, signal_name):
instanced_dice.connect(signal_name, self, "_on_dice_signal")
func _on_dice_signal(argument):
#do stuff
This is just one possibility, of course. You could add various if-statements to the code, routing to different functions. For example:
gameboard.gd
var global_listener = get_node("/root/globallistener")
var new_dice = dice_scene.instance()
#add_child and position your stuff here
new_dice .connect("rolled", self)
global_listener.connect_dice(new_dice, "rolled")
global_listener.connect_dice(new_dice, "discarded")
func _on_dice_rolled(argument):
#do stuff
globallistener.gd
func connect_dice(instanced_dice, signal_name):
if signal_name == "rolled":
instanced_dice.connect(signal_name, self, "_on_dice_rolled")
elif signal_name == "discarded":
instanced_dice.connect(signal_name, self, "_on_dice_discarded")
func _on_dice_rolled(argument):
#do stuff
func _on_dice_discarded(argument):
#do stuff
Again, the code is not tested as I'm at work. But I think there are a lot of possibilities to achieve your wanted behavior.