States allow you to modify your object in an organized, type-safe, way. States can also be previewed when the game is running in edit mode, speeding up iteration. States are a lightweight alternative to using inheritance, and can even be used to change a Screen or Entity multiple times. States can exist on any Screen or Entity, and appear under the States folder in the FRB Editor tree view.

Although states can be added as either categorized or uncategorized states, categorized states are the most common, and avoid confusion which can be caused by uncategorized state.

The following image shows a PowerUp entity with a PowerUpCategory containing three states.

Adding States

The FRB Editor provides two different ways to add states. The preferred method is using the State Data tab. The second way is using the right-click menu. The two can both be used, so you don't have to pick which to use; that said, using the State Data method can be easier, so it is recommended.

State Data

Once a category has been created, states can be added in the State Data tab.

New states can be added by entering names in the left-most column. Adding a new name creates a new state.

By default, variables do not appear in the State Data tab (and are not accessible by states in the category). You must explicitly add variables which you would like to edit in your state. Conceptually, this makes sense considering categories are usually built to only modify a subset of variables.

For example, consider a variable which tunnels into a Sprite's CurrentChainName - which we'll call "Animation" to keep the name short:

To make this variable accessible to the PowerUpCategory, drag+drop the variable onto the category. Doing so results in the variable appearing in the State Data grid.

Variables can be added and removed from the State Data tab for a given category as an alternative way to include and exclude variables.

Right-Click Menu

States can also be added through the right-click menu on a category.

This method is the old way of adding states. It is still supported, but it is a little more cumbersome compared to using state data. States added this way will still appear in the State Data tab.

Setting States in Code

Every state category generates a class which is embedded in the screen or entity containing the state. By default states can only be assigned inside the entity or screen defining the state. For example, if the PowerUp entity defines a state category named PowerUpCategory, then states can be assigned in code.

Assigning the state will apply all variables set in the state in the FRB Editor.

Conditional Logic Based on State

The state can be compared against the values which are assigned to perform logic. For example, the following code could be written to perform logic based on the state of the power up.

if(this.CurrentPowerUpCategoryState == PowerUpCategory.FirstState)
  // Do logic for first state
else if(this.CurrentPowerUpCategoryState == PowerUpCategory.SecondState)
  // Do logic for second state
// and so on...

Last updated