How to pass a value from node a in scene b to node x in scene y?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bertoldo

I am very new to GDscript and I’m currently working on a turn-based battle system. The problem I’ve encountered is that I cannot find a working way to pass a value from the overworld to the battle scene, I want to pass an enemy class object for example and use it in the battle scene for archiving a fully reusable scene, however passing an already created object enemy (with all values in it as part of the class) doesn’t work, passing the values themselves to then “assemble” the enemy in the battle scene doesn’t work either. I’ve tried with signals and also without, trying all ways that came to mind and realized maybe this isn’t possible. I know the battle scene can be archived by pausing the current tree and adding the new one on top but before that I’d like to try doing it like I initially envisioned, if possible.
So is there a way to do this?
I cannot paste all the codes i’ve tried beacuse I changed a lot of them, currently I have it as:

#class declared separatley with all values set to null and a single setter (similarly to a constructor in c++) for all functions

#enemy overworld collision event
    func _on_body_entered(body):
    	if body.is_in_group("player"):	Script.emit_signal("get_enemy", argument 1 ... argument n)

#singleton for signals
       signal get_enemy(argument 1 ... argument n)

#signal reciever in second scene
      func _ready():
	BattleScene.connect("get_enemy", self, "create_new_enemy")

(All these of course in their respective nodes as commented)
Yet trying to use the values in create_new_enemy doesn’t yield anything. I’ve read through and through the documentation not being able to find anything. I know this isn’t probably the correct way to do it but I tried everyhing i could by now and I’m really frustrated by not being able to find a solution.

Thanks in advance to anyone willing to help.

:bust_in_silhouette: Reply From: djmick

You could make a global script that is autoloaded so that every script in the game can get its values. This video explains a bit about singletons. It might be a bit complicated but I think it would work.

You could have a variable in the global script like current_enemy, and when you bump into an enemy in the overworld, it set the global scripts current enemy to that enemy, then when you get into the battle scene, you can access the global variables current enemy variable to use that enemy. I hope this all makes sense, and I hope this helps.