Access Variables from Script

M

MhmadHani

Guest
Am trying to make a script that contains all my global variables.
How to access it from objects.
 

Cpaz

Member
Global variables have to be declared just like any other variable.
All you need to do in this case is call the script wherever needed (be it a config/controller object, etc).
Then it should be as simple as calling the variable like normal.

IE: `global.myGlobalVariable = "some unrelated value";`

The manual goes into a little more detail on specifics, so I'd recommend checking the "global variables" section: https://docs2.yoyogames.com/
 
Last edited:

Yal

šŸ§ *penguin noises*
GMC Elder
1) Run the script before you do anything else in the game (e.g. the Game Start event of the titlescreen object). It contains a bunch of code like
GML:
global.my_variable = 64;
global.breath = "bad";
2) Now all variables have been created. Access them using their variable names like normal (global.my_variable and global.breath in my example). Note that the "global" is part of their name.
 
M

MhmadHani

Guest
Global variables have to be declared just like any other variable.
All you need to do in this case is call the script wherever needed (be it a config/controller object, etc).
Then it should be as simple as calling to variable like normal.

IE: `global.myGlobalVariable = "some unrelated value";`

The manual goes into a little more detail on specifics, so I'd recommend checking the "global variables" section: https://docs2.yoyogames.com/
Thank you
 
Top