save current level (root node) for a gameover resart level?

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

i need help on a way to store the current root node of my levels so that my gameover screen (which is a seperate scene) can restart which ever level the player is in.

my gameover script

    extends Control

func _on_Button_pressed():

my player script (the part which calls in the gameover scene)

	if health <=0:

level 1 and 2’s node hierachy

:bust_in_silhouette: Reply From: njamster

You need to add an AutoLoad (i.e. a script that isn’t replaced when you change the current scene), store the path of the current level there and then reload that path on gameover. Let’s say your AutoLoad is accessible as a Singleton called Global:

# include this in the scripts of your level scenes
func _ready():
    Global.current_level = self.filename

# include this in the script of your deathscreen