Ending a game

Ending game is easy to be done via the game_end command but however there is a problem in Game Maker. When you have "Let Escape end the game" checked in the Global Game Settings the game will end when the user hits the X (close) button but however will also end when the user presses escape on the keyboard. Most Program writers don't like this. However a simple peace of code can solve this. Before using this code uncheck the "Let Escape end the game" in the Global Game Settings.

if you are not running the game/program in loop (some do) you can use the escape keyboard event (not the pressed or released) and run the following code :

{    if (!keyboard_check_direct(vk_escape)) { game_end; } }

If you are running your game inside a loop or you want to check while in a loop you can use :

{    io_handle; //get keyboard state manually (since we are in a loop) if (keyboard_check(vk_escape)) { if (!keyboard_check_direct(vk_escape)) { game_end; }    } }