gnysek
Member
GM Version: Studio
Target Platform: Windows
Download: NA
Links: NA
Generally, most of GameMaker:Studio users initialize all needed global variables and external extensions in a special room at start of game, and then go to next room, and never back there.
A downside is, that you cannot use game_restart(); this way. However, there is a way to do it and execute at start of game, but before whole GM:S runner engine starts, and game_restart() will restart game to a moment AFTER this script was executed, so it will be for sure ran only one time! Also, you don't need any objects/room/room creation code to do it!
So, create a script which initializes all your variables, lets call it script_init. Put all code you need. Then, at top of script, add this line:
That's all. It's undocumented, but if you have opportunity to test GM:S2 and import existing game, then you find it's used there for compatibility scripts. Since GM:S and GM:S2 share same runner (or very similar), it works on GM:S 1.4 also!
You can add more scripts to it if you need to divide code, you can also refer to a different script than current one. It doesn't matter, since it's not a function in fact, but a directive to pre-compiler, so it's removed from scripts during compile time (calling script which have gml_pragma() inside won't execute it again).
Target Platform: Windows
Download: NA
Links: NA
Generally, most of GameMaker:Studio users initialize all needed global variables and external extensions in a special room at start of game, and then go to next room, and never back there.
A downside is, that you cannot use game_restart(); this way. However, there is a way to do it and execute at start of game, but before whole GM:S runner engine starts, and game_restart() will restart game to a moment AFTER this script was executed, so it will be for sure ran only one time! Also, you don't need any objects/room/room creation code to do it!
So, create a script which initializes all your variables, lets call it script_init. Put all code you need. Then, at top of script, add this line:
Code:
gml_pragma("global", "script_init()");
You can add more scripts to it if you need to divide code, you can also refer to a different script than current one. It doesn't matter, since it's not a function in fact, but a directive to pre-compiler, so it's removed from scripts during compile time (calling script which have gml_pragma() inside won't execute it again).
Last edited by a moderator: