game_change

This function ends the current game and launches another game that's included in the Included Files.

It allows you to have a main game from which you can launch other games that you keep in a different GameMaker project. The function can be called again in the launched game to return back to the main game.

The function is supported on the Windows, macOS, PS4, PS5 and Switch platforms.

IMPORTANT This function only works in VM builds.

IMPORTANT GameMaker names the .win file differently depending on whether your game is running from the IDE or from the final executable (created using Create Executable in The Build Menu). When running from the IDE the name will be $"{game_project_name}.win", if not it will be "data.win". You should always make sure to refer to the right name, e.g. by setting up a different configuration.

NOTE Since the child games' external files are included in the main game's datafiles, they can be accessed from the main game as well.

Usage Notes

Argument Values Per PlatformArgument Values Per Platform

The table below provides an example of the working directory and launch parameters to be provided on each of the supported platforms: 

PlatformWorking DirectoryLaunch Parameters
Windows"/game2""-game game2.win"
macOS"game2"""
PS4/PS5"""-game /app0/games/game2/game.win"
Switch"rom:/game2/"""

 

Syntax:

game_change(working_directory, launch_parameters);

ArgumentTypeDescription
working_directoryStringThe working directory of the game to be launched
launch_parametersStringThe command-line parameters to pass to the game to be launched

 

Returns:

N/A

 

Example 1: Launching an Included Game (on Windows)

game_change("/chapter3", "-game chapter3.win");

The above code runs from the launcher game and launches the "Chapter 3" game, which is stored in a subdirectory "chapter3"  under Included Files.

 

Example 2: Returning to the Main/Launcher Game (on Windows)

game_change("/../", "-game main_game.win");

The code above runs from a game that was launched from the launcher game and returns to the main/launcher game. The double dots .. indicate that the game's working directory is one above the current working directory.