# SStateMachine

**Membres** 11

|           |                                       |                                                                                                                                              |
| --------- | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| Fonction  | [NextState](#nextstate)               | Enter the next state                                                                                                                         |
| Fonction  | [PrevState](#prevstate)               | –                                                                                                                                            |
| Fonction  | [SetState](#setstate)                 | Enters the state of being set that its order is "state"                                                                                      |
| Fonction  | [BindToUI](#bindtoui)                 | The state machine will bind itself to all Toggles, Buttons, Dropdowns and Sliders on the SGameObject it is in or on a specified SGameObject. |
| Propriété | [Enabled](#enabled)                   | Whether the simple state machine component is Enabled or not                                                                                 |
| Propriété | [StateCount](#statecount)             | Total number of States.                                                                                                                      |
| Propriété | [StateNames](#statenames)             | A list of the names of all States.                                                                                                           |
| Propriété | [CurrentState](#currentstate)         | The index number of the current state.                                                                                                       |
| Propriété | [CurrentStateName](#currentstatename) | The name of the current state, or null if no state.                                                                                          |
| Propriété | [ComponentName](#componentname)       | The name of this component.                                                                                                                  |
| Propriété | [GameObject](#gameobject)             | The GameObject this component is attached to.                                                                                                |

## Fonctions

### NextState

void NextState()

Enter the next state

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.StateMachine.NextState()

```

### PrevState

void PrevState()

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.StateMachine.PrevState()

```

### SetState

void SetState(int state)

void SetState(string state)

Enters the state of being set that its order is "state"

Paramètres

| Paramètre | Type   | Description                                                  |
| --------- | ------ | ------------------------------------------------------------ |
| state     | int    | The index of the state. First state is 1.                    |
| state     | string | The name of the state as set in the State Machine component. |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.StateMachine.SetState(2)
--or
Space.Host.ExecutingObject.StateMachine.SetState('A State Name')

```

### BindToUI

void BindToUI()

void BindToUI([SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md) go)

The state machine will bind itself to all Toggles, Buttons, Dropdowns and Sliders on the SGameObject it is in or on a specified SGameObject.

Binding to Button : Clicking button will call NextState()<br />Binding to Toggle: Toggle On sets State to 1, Toggle Off sets state to 2<br />Binding to Dropdown: Selecting will set State to that selection's caption text<br />Binding to Slider: Moving slider changes State to slider value

Paramètres

| Paramètre | Type        | Description                                                   |
| --------- | ----------- | ------------------------------------------------------------- |
| go        | SGameObject | A specific SGameObject which this State Machine will bind to. |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.StateMachine.BindToUI()
----or
Space.Host.ExecutingObject.StateMachine.BindToUI(Space.Host.GetReference("a reference"))

```

## Propriétés

### Enabled

bool Enabled {get; set; }

Whether the simple state machine component is Enabled or not

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.StateMachine.Enabled = false

```

### StateCount

int StateCount {get; }

Total number of States.

Exemple

**Lua**

```lua
numberOfStates = Space.Host.ExecutingObject.StateMachine.StateCount

```

### StateNames

string\[] StateNames {get; }

A list of the names of all States.

Exemple

**Lua**

```lua
tableStateNames = Space.Host.ExecutingObject.StateMachine.StateNames

```

### CurrentState

int CurrentState {get; }

The index number of the current state.

Exemple

**Lua**

```lua
currentState = Space.Host.ExecutingObject.StateMachine.CurrentState

```

### CurrentStateName

string CurrentStateName {get; }

The name of the current state, or null if no state.

Exemple

**Lua**

```lua
currentStateName = Space.Host.ExecutingObject.StateMachine.CurrentStateName

```

### ComponentName

string ComponentName {get; }

The name of this component.

Exemple

**Lua**

```lua
componentName = Space.Host.ExecutingObject.StateMachine.ComponentName

```

### GameObject

[SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md) GameObject {get; }

The GameObject this component is attached to. A component is always attached to a GameObject.

Exemple

**Lua**

```lua
theGameObject = Space.Host.ExecutingObject.StateMachine.GameObject

```
