0 votes

I have a variable "example" on autoload scene "scene"
how to synchronize it in another scene so as not to constantly use "scene.example"

for example, I use

var examp = scene.example

and I want to when changing "examp" changed and "scene.example"

in Engine by (83 points)

1 Answer

0 votes

You could define setget functions for your variable:

Inside those functions you return or set the value of the global variable.

If you are adressing the contents of complex data types (dictionaries, objects, arrays) you can also assign that variable to a local var which then (always) receives a kind of pointer.

So if you define a dictionary in scene:

var my_settings = {"audio_volume":0.5, "cheat": false}

Then you could copy that dictionary "pointer" to a local var and use that instead:

var glb_settings = scene.my_settings

glb_settings["audio_volume"] = 0.75
print("cheat is: "+str(glb_settings["cheat"]))

Although all this is not very "transparent" and may be difficult to understand if you (or someone else) looks at the code at a later time. So I opt for just referencing the global singleton. (i.e. scene.example).

by (3,258 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.