Question: How do you quit a game in GameMaker?

Answer

To quit a game in GameMaker, you can use the built-in GameMaker Language (GML) function game_end(). This function will close the game window and terminate the program. It's very simple to use; just call the function whenever you need to end the game, such as in response to a player's action like pressing an "Exit" button.

Here is an example of how you might use it in code:

// The following would typically be placed in the button's event or a keyboard check conditional if (keyboard_check_pressed(vk_escape)) { // Check if the Escape key was pressed game_end(); // Quit the game }

If you're using GameMaker Studio 2 and want to ensure that the game closes properly on all platforms, you should also consider using the os_set_quit() function before calling game_end(). This is particularly important for ensuring consistent behavior on platforms like iOS or Android.

Here's how you might use both together:

// Code to quit the game, potentially in an exit button's Mouse Left Pressed event os_set_quit(); game_end();

By setting os_set_quit(), you tell GameMaker that the next step should be to close down the game cleanly on mobile devices or other platforms which have specific requirements for exiting applications.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.