Finite State Machine Plugin and Behavior

Dream it, build it!

Finite State Machine Plugin and Behavior

Finite State Machine Plugin

Finite State Machine Global Plugin for C3 allows you to create and manage global game states to better structure your game events and overall flow. By implementing Game States you add another layer of control to your game flow, and you can group events to happen only while the specified Game State is active, achieving a more organized flow and preventing the game from behaving erratical due to undesired conditions (overclicking a button to chage a state, missreviving the player after dead, locking up while reading resources, etc.) Game States are custom, you can set up your own names for readability, the plugin provides you with ACEs sufficient to control what happens during each state.

Why using a FSM?

Events in Construct can turn messy very quickly if you are not an experienced developer with self organization costumes and discipline. A way to improve your code's structure is by creating general states for your game; your game may have the following states: GAME_LOADING, GAME_READY, GAME_STARTED, GAME_PAUSED, GAME_COMPLETED, GAME_CINEMATIC, etc. Then tie all the game logic to the corresponding state, for instance, while the GAME_LOADING state is alive, no player input is allowed nor UI interactions are permited and all your inputs should evaluate the game state provided by the FSM plugin.

For the mentioned states, a game flow may happen as follows:

  1. Your GAME_LOADING state is set for the whole game, here you can load texturs, config, create the initial scene, prepare the general input, retrieve information from your backend services, etc. No player input is allowed during this state.
  2. After GAME_LOADING has been completed, change the state to GAME_READY. During GAME_READY, your game can show a transition, notify the player that the game is ready to start, transition to the Menu layout to wait for the player selection. Player input is now permited to allow the player to interact with the Menu and start the game.
  3. State GAME_STARTED indicates that your game has started, gameplay is running and the player is having fun. Player input is permitted and you may limit it to only what is related to the gameplay.
  4. When the player finishes your game, you can change the state to GAME_COMPLETED, show a winning screen, score, prevent gameplay-related player input, enable UI input to exit the layout and call your backend services to store player's data.
  5. During gameplay you also have the option to either pause the game or play a cinematic with the events GAME_PAUSED and GAME_CINEMATIC correspondingly. In both states you may hold the player from interacting with parts of your game, and also stop any other event/animation from happening. After either states are completed, you can trigger the GAME_STARTED state back to continue playing.

Actions


Change State

Changes the FSM state to the one specified.

Parameter Description
State State name (string)

Conditions


On State Changed

Triggered when the indicated state is set by the action Change State

Parameter Description
State State name (string)

On State Finished

Whenever you change the state of the FSM, the current state is marked as finished and the On Finished state is triggered. The new state won't be processed by this event at this point.

Parameter Description
State State name (string)

On Any State Changed

Triggered on any state change.

Compare Current State

Evaluates if FSM's current state equals the input string

Parameter Description
State State name (string)

Compare Previous State

Evaluates if FSM's previous state equals input string

Parameter Description
State State name (string)

Expressions


GetCurrentState

Returns the current FSM state

GetPreviousState

Returns the previous FSM state