0 votes

Hello

How can i use variables, stored in an autoload globals singleton script with other visual scripts?

Godot version v3.4.3
in Engine by (75 points)
edited by

1 Answer

+1 vote

Take whatever the name of your global GD file is, load it in Autoload in the Project Settings, (you will also need a Node of some sort to autoload as well, likely whatever "System" or Scene-change type handler you are making) then you can call whatever you need to from that file using that name then a period for what you are calling.

So let's say you have a file that is called Global.gd and you autoload it at start. It has this script:

var roundTime = 10

func onRoundEnd():
     ## do something here

So to call those in your other scripts, you would put:

Global.roundTime = 20
Global.onRoundEnd()

Just be aware to change these values you need to call them directly (like I just did above). You can't store their value in a local variable and then change that to alter the global.

by (498 points)

I know how to do it in godot script.
there i can do it just by having the script in autoload.

I specally want to know to do it in visual script.

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 Frequently asked questions and 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 [email protected] with your username.