Legacy GM [SOLVED] Differenciate IDE from Executable

M

mikahon

Guest
Hi,

Is there any way to know if the game was launched either from the Game Maker IDE or from a created executable ?
 
M

mikahon

Guest
Well, debug_mode tells you whether you used the red arrow (F6), so no it's not what I'm looking for, unless I set to myself the rule that every development test should be done exclusively in debug mode, which is not a valid option.
 

Llama_Code

Member
Not sure of an exact command for this but there are two ways I can think of to do this...

One is to use a variable, set it to 1 if your testing and remember to set it to 0 when you create an executable, or use a constant if your concerned about manipulation.

Another option is to check for the existence of a file named myproject.win. When you run it through the IDE it uses runneer.exe to launch a .win file. So if your game is named Driver it would be Driver.win. This file won't exists if you run it straight from a a created .exe, so if the file exists its being launched from the IDE.

Code:
if file_exists("mygame.win")
    {
    ide = 1;
    }
else
    {
    ide = 0;
    }
 
M

mikahon

Guest
Not sure of an exact command for this but there are two ways I can think of to do this...

One is to use a variable, set it to 1 if your testing and remember to set it to 0 when you create an executable, or use a constant if your concerned about manipulation.
This is the solution I want to avoid by all means, since I know there will be that one time where I'll forget about it.
Another option is to check for the existence of a file named myproject.win. When you run it through the IDE it uses runneer.exe to launch a .win file. So if your game is named Driver it would be Driver.win. This file won't exists if you run it straight from a a created .exe, so if the file exists its being launched from the IDE.

Code:
if file_exists("mygame.win")
    {
    ide = 1;
    }
else
    {
    ide = 0;
    }
Correct me if I'm wrong, but you mean "mygame.win" is supposed to be a file in the executable folder ? if so, isn't the function file_exists only working in the working_directory folder due to file limitation system ?
 

Llama_Code

Member
The win file is the project file that is in your project folder when you do a test run, and this it where the game is run from when you do a test run so that is essentially your working directory because of the way the testing works. So if you launch from within the IDE that win file will exist in your working directory.

When you run the game from rhe IDE pay attention to end of the complie window and you will see where your game is run from, you will see something like:

"C:\Users\your_name\AppData\Roaming\GameMaker-Studio\Runner.exe" -game "C:\Users\your_name\AppData\Local\gm_ttt_6807\gm_ttt_68974\yourgame.win"

That is where it runs your game from. You could test this further with a test object, simply create an object and put this in the draw event:

Code:
draw_text(20,20,working_directory)
run it and you will see that this location is your working directory when testing.

If you build a stand-alone exe that mygame.win file won't exist and you working directory will be in your AppData\Local\Temp folder.
 
M

mikahon

Guest
Although this isn't an official way, I gotta say it works fine.

Creating a macro RELEASE_MODE that is equal to
Code:
!file_exists(working_directory + "game_name.win")
returns false when running the game in the IDE, and returns true when running it from an installed version.

I see 2 downsides though (maybe you'll be able to adress them ?) :
- Does this method applies to every platform (especially consoles) ?
- Does this method have any chance of becoming obsolete during an update or in GMS 2 ?
 
Last edited by a moderator:

Llama_Code

Member
I know it works for iOS and Android, it should really work for any export because you will build it on the PC regardless.

It does work in GMS 2 as well.

As for becoming obsolete, well, you can't even guarantee official functions won't become obsolete in future versions since it happens all the time.
 
Top