SOLVED Does declaring many global variables at the start of a game slow loading time down?

otterZ

Member
In the project I am working on I have around 200 global variables being declared and initialised in a Create event in the very first room (start up screen). As I add more content to the project I could end up with 1000+ global variables, so my question is this . . .

Does declaring and initialising a thousand or so variables at the start of the first room of the game slow loading time down? Would it be better to split global variable declarations up instead if this is the case? Or would declaring 1000+ global variables at the start of the game have hardly any effect on loading of the first room?

The 200 or so global variables I have declared in a Create event in a controller object in the very first room so far have not slowed loading time. However, I have no experience as to whether 1000+ global variables would. Would it be like the blink of an eye or a 6 second slowdown or something like that?

[Please note: I am deliberately using global variables, as the values they hold need to be accessed in many parts of the app/game.]
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Assigning variables is FAST so I wouldn't worry about it, especially if you are doing it at the start of the game. GameMaker games load very quickly anyway, so even if there was a few extra microseconds added when you create those globals, I don't think most people would notice or care. :)
 

pj_Yama

Member
Hard to say how much it will affect your game without debugging, the best bet will be to dive into the Debugger to check memory usage and see how it scales as you add more variables. Global variables are retained in memory until the end of the game, so they definitely will affect memory but i would imagine it's a negligble amount depending on what else is happening and what type of data you're storing.

This many global variables could quickly become very cumbersome to manage though - so the question would be.. do you need to store all of these values as individual global variables or could you aggregate some of the data using another method such as a ds_map?
 

TheouAegis

Member
No matter what you're going to have an FPS pick up at the very beginning anyway because the operating system is also running a bunch of stuff when your program for starts up. So it's hard to measure anyway. Typically, people expect some degree of startup lag. Even if you spread it out, all you are doing is preventing slow down, which wouldn't be noticeable anyway because nothing has happened yet. Have you ever played a game with a loading screen? Loading screens are there because trying to do everything in one step causes slowdown; if the slowdown is too great, the player may think the program has frozen up completely; a loading screen let's the player as well as the programmers know everything is still running smoothly, not to make things run faster.
 
Last edited:

otterZ

Member
@Nocturne : That basically sums things up in a nutshell. I don't have to worry about that now, which is great.
@pj_Yama : Interesting about using a ds map, I have used ds lists before but not ds maps yet, I will look into these as I enjoy learning new things.
@TheouAegis : That was interesting about using loading screens to mask initial start up lags in some games.

Thank you guys.
 

Roderick

Member
You know all those splash screens you see at the beginning of most games, and how you can't skip them until they've been up for a couple seconds? That isn't just to tell you who worked on the game; there's initialization happening in the background.

If you think there's going to be enough setup time to cause a delay, hide it behind a splash screen so that the user doesn't think the program has frozen. Also consider a loading bar if it takes more than a few seconds.
 
You know all those splash screens you see at the beginning of most games, and how you can't skip them until they've been up for a couple seconds? That isn't just to tell you who worked on the game; there's initialization happening in the background.

If you think there's going to be enough setup time to cause a delay, hide it behind a splash screen so that the user doesn't think the program has frozen. Also consider a loading bar if it takes more than a few seconds.
Exactly. I have such screens in my FPS not just for style, but to load everything relating to the view models (including animations) because those are the assets that don't get removed from memory when exiting the campaign or multiplayer in order to minimize loading into those modes.
 
Top