Game States

Game states help to define the logical structure of a game. As you leave the menu to play the game and then maybe open the inventory screen, you have switched through three different states of the game that have to perform different tasks. Each state will handle events differently and draw something different on the screen.

Reality Factory manages these various situations through three different states:

Each of these states has its own default (invisible) GUI window that acts as parent for all other GUI elements in that state. In this way, when switching between states, it is sufficient to just show/hide the state's default GUI window to show/hide all of its child windows.

For the inventory and message definitions this means that you have to specify the game state you want them to appear in (i.e. play state or dialog state, where the former can only be used if the player is not controlled by mouse input).

Menu State

The menu state renders the game menu and allows to manage general game settings and savegames. It solely reacts to GUI events. Starting a new game, or pressing the Esc key while a game is running will switch the engine to the play state.

Play State

The play state renders the actual game level and handles input to control the player. If the player is not controlled by the mouse this state may also handle GUI events. Pressing the Esc key in this state takes you back to the menu state.

Dialog State

The dialog state is meant for game situations that do not require direct control of the player, i.e. conversations, inventory or messages involving user interaction. Updating and rendering of the actual game level is optional in this state.

Enter and Exit Dialog State

Instead of automatically entering the dialog state when activating a conversation or the inventory, the corresponding GUI layout will receive a show command and you get the chance to do some setup beforehand by using the Shown GUI event (see GUI Event Reference and Handling GUI Events from Simkin).

To actually switch to the dialog state and make the layout visible you simply use the following script method:

DialogState.Enter();

To return to the play state you will have to call:

DialogState.Exit();

Upon exiting the dialog state all conversation, inventory or message layouts will be automatically hidden again.