![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | start123 |
I want all the variables in one script to be used in other scripts. How should I do it?
![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | start123 |
I want all the variables in one script to be used in other scripts. How should I do it?
![]() |
Reply From: | jgodfrey |
The easiest way is to create a singleton
script. The items in that script can be directly accessed from other scripts.
Globals.gd
)Singleton
is checked)Now, to access anything in it (say a playerSpeed
variable), just preface the reference with the script name. For example:
var mySpeed = Globals.playerSpeed
Also, note you can have multiple singleton scripts if you want.
You can also add functions and use the _ready() function of the Singleton.
deaton64 | 2020-05-15 14:23
How can I make such a command with an image or a number.
start123 | 2020-05-19 11:44
Not quite sure what you’re asking.
But you can use the Global variables from anywhere in your code and set the values to what you want.
deaton64 | 2020-05-19 20:11