Where to store back-end data / global variables?

  • Thread starter Beyond Disbelief
  • Start date
B

Beyond Disbelief

Guest
Hi,

I'm new to GMS and while I appreciate how streamlined it is it has me confused.. is everything declared ad hoc? I see that all functions and variables are declared within an event which are affixed to an object or a room. How does one manage back-end data and global variables?

I want a centralized location to declare and store them so I can be sure any time any object needs that information its already calculated. As it is it is very confusing which object would be doing the declaration in runtime and what is passing to where.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Everything is declared when the code that declares it runs... when that is depends on where said code is.

If your code is in a script, it will run when the game starts. So if you want "a centralized location to declare stuff", that would be a script.
 

Mr Magnus

Viking King
Either you have a "controller" object that's persistent and handles storing and organizing your stuff, or you use global variables which are not bound to anything and always exist after being declared.

Script files (after 2.3) are all automatically executed at the start of the game, which is why functions declared in them are globally accessible. Declaring global datastructures that need to always exist there is a good idea if you plan on using them, and then you can also create some helper functions to work with them in the same spot.
 
Top