Keeping values independent of Scenes

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

Hi all.

I had a look at Autoload, and figured it would work pretty well for things like holding High Score values, Team Names, and player-picked color values. Thing is, though, I don’t exactly know how that would look, and was wondering if anyone could provide a basic example?

:bust_in_silhouette: Reply From: Magso

Singletons/Autoload scripts are basically nodes that are children of the root and the same level in the hierarchy as the current scene node. They are referenced by the node’s name which doesn’t necessarily have to be the script’s name and the variables can be accessed directly through that.

e.g. in the autoload tab

name: the_autoload    path: res://my_script.gd

my_script.gd which is the autoload script.

extends Node
var my_var = 5

Another script in the scene.

print(the_autoload.my_var)

prints 5