GM: Ending a game

From GMpedia.org Wiki

Jump to: navigation, search

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. Please Note that I didn't find this out by my self, I happen stumble apon a post on the GMC years ago (forgot who). Before using this code please 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();
        }
    }
}


[edit] See Also

Personal tools