Windows Detect if game is compiled, or was launched via IDE (script)

GM Version: 1.4 + 2?
Target Platform: Windows
Download: N/A
Links: N/A

Summary:
Is your game compiled for deployment as an .exe, or is it being launched through game maker's IDE?

Code:
GML:
///game_is_compiled()
/*
Returns if the game is running via the IDE or if it's compiled
*/

// Is the game being launched via runner.exe? (result inverted).
return 1-sign(string_pos("Runner.exe",parameter_string(0)));
Compatibility:
- This works on windows (regular + YYC), for GM1.4.
- It could work with GM2 (windows), but it may need a minor tweak if GM2's runner is differently named.
- It is SAFE but doesn't work with GM2 mac. parameter_string(0) is just empty. This simply means that the script will say the game is compiled even when it's launched from the IDE.
- It will break if your game is literally called "runner.exe". In this very rare case you could fix it by extending the check to include the \GameMaker-Studio\ folder as well.
- It could work on other platforms, but you'd have to check first. Post results below!

How it works:
code_is_compiled() exists already, but it returns whether the game was compiled using YYC / JS, not whether the game was launched from the IDE.

parameter_string(0) returns the path to your game's exe file.
This can also be used if you want to detect if the player has renamed the executable! Could possibly even automate it by checking it against the game name in the working_directory path.

When your game is compiled using the IDE, this path will always point to:
C:\Users\user\AppData\Roaming\GameMaker-Studio\Runner.exe

But if your game is compiled as an exe, it will point to the location your game is running from, either:
C:\... etc ...\YourGame.exe
or
C:\Users\user\AppData\Local\Temp\IXP006.tmp\YourGame.exe
if you used the standalone exe extractor option when you compiled.

Example of use:
Can be used as a one liner check as to whether you should enable/disable a dev feature, without the need to access the hard drive to check for a 'hidden' file you created beforehand that only you have.
GML:
// If the game isn't compiled
if !game_is_compiled()
    {
    // Enable dev features
    }
 
Last edited:

gnysek

Member
This is clever, but I'm not sure if it's good idea to keep whole code and descriptions in spoiler, as this way it seems that game_is_compiled( is built-in function :p

I will definitely use it in my projects from now on.
 
Top