ERA-Engine-Godot-Document Help

Setting States

Overview

In the FSM Mode, the game in general is transiting among states, so the main part of the game is the state scripts.

Create Your First State

State scripts are in general the same. Here, let's take the first state --main state as an example.

  1. Create and Edit the main_state.gd

    1. Find the ./GdsScript folder, where all your game scripts will be saved here if you code your game in GD Script.

    2. Here, you will find 2 folders: Data and Flow. The former one is used to save all data files, while the latter is the one to save your game scripts.

    3. Create a file called main_state.gd under path ./GdsScript/Flow. This is the default name of the initial state.

    4. Now, finish the basic structure of your file as below:

      class_name MainState extends Flow # Declare the file is coding a state by 'extends Flow' # Declare the state name by 'class_name MainState'
  2. Write the State

    • Create a main_state function as the enterpoint of this state:

      func main_state(): TXT("era靛紫档案") # Create a text unit BOX([ # Create a series of units, pack in a box BTN("开始游戏", "start_game"), # Create a button unit, and set corresponding next state name BTN("读取存档", "load_game") ])
  3. Next State Functions

    1. Setting next state functions with following codes:

      func start_game(): TXT("你喜欢什么样的主角?") BTN("喜爱淑女的主角", "select_char_0") BTN("财大气粗的主角", "select_char_1") BTN("神父气质的主角", "select_char_2") BTN("流氓热血的主角", "select_char_3") func load_game(): TXT("读取存档") BTN("读取不了,返回", "main_state") # Continue with select_char_0, select_char_1, select_char_2, select_char_3...
    2. Follwing such work flow, you can build your first minimal game.

23 August 2025