# State Machine

> Aego 0.12.5 · development; docs build `4a32b816933e02930662f6a443cb25abe6050d090c55e237cbff5c44ae9b25f8`. [Build manifest](/docs-build.json).

```
component gameplay.StateMachine
```

Named states with Enter, Exit, Fixed and Update hooks found by name on the node's scripts: EnterRun(), ExitRun(), FixedRun(dt), UpdateRun(dt). Scripts change the state with Go.

## Fields

| Name | Script name | Type | Default | Description |
|---|---|---|---|---|
| States | `States` | `[]string` | `[1 items]` | State names, also the suffix of the hook methods. |
| Initial | `Initial` | `string` | `"Idle"` | State entered when the node starts, after the scripts' Ready. Empty uses the first state. |
| Current | `Current` | `string` | `""` | Runtime state. State now. |
| Previous | `Previous` | `string` | `""` | Runtime state. State before the last change. |
| Time | `Time` | `float` | `0` | Runtime state. Seconds of fixed steps spent in the current state. |
| Index | `Index` | `int` | `0` | Runtime state. Index of the current state in States. |

## Go

```
func (StateMachine) Go(state string) bool
```

Switches to a state after the current hook returns; Exit of the old state and Enter of the new one run in between. Returns false for an unknown state.

## Is

```
func (StateMachine) Is(state string) bool
```

Reports whether the machine is in a state.

## TimeIn

```
func (StateMachine) TimeIn() float
```

Returns the seconds spent in the current state.

## Changed

```
signal Changed(from int, to int)
```

Fires after a state change with the indices of the old and the new state.
