Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Bertoldo |
Hi,
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)
get_tree().change_scene("res://BattleScene.tscn")
#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.