How to reload the entire game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ArAdev
:warning: Old Version Published before Godot 3 was released.

Hi I´m having problems with the programming of my game with the death of the player. The thing is that I´m trying to use the get_tree().reload_current_scene() in my world node, it just works fine but the problem is that the auto load scripts that I have get their variables cleared, making unplayable my game, because there´s a crash when some action happened in them because the variables are null.
The question is how can I make the “global” scripts to be updated(“recapture” the variables again) when I restart the world scene? Consider that this scripts are stored in the “root node” and not in my “world” scene. Thanks in anticipation
Edit: I commented the response of eons giving some important details to this question, if someone knows how to fix it, I would appreciate a lot.

The method reload_current_scene should not affect the autoloaded scripts, how is that variables get cleared on them too?

eons | 2018-01-03 02:34

I checked again and apparently , the only variables that are cleared are the ones that have a node inside them( with get_node()), the others are fine(they are arrays and dictionaries and variables from the inside of the node). Apparently I can fix this by getting the nodes inside the process code, but that would mean I have to rewrite a lot of code. If someone know if you can make the auto load scripts to “reload it´s call to the get_nodes and another external variables” I would appreciate it a lot.

ArAdev | 2018-01-03 03:00

:bust_in_silhouette: Reply From: eons

Connect the autoloaded scripts to the exit tree signal of the scenes where they get the nodes, after receiving the signal, it should wait for the scenes to load, set values and connect again.

Another option is to make the autoloaded scripts store the NodePath instead, if the scene is reloaded, the path may stay the same (depends on the scenes).

Thanks man, the method of making the variables the path worked perfectly, I had to rewrite a bit the code but with the replace tool of the gdscript editor it wasn`t that bad.

ArAdev | 2018-01-04 05:23

I’m having trouble coding games too. Thanks for good idea to solve the problem.

strangemedina19 | 2021-08-23 04:38