---
name: "execFSM"
type: command
status: ok
groups: ["Program Flow"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/execFSM
revid: 363581
updated: 2024-04-07T14:49:31Z
---

# execFSM

*Command · Program Flow · Arma 3 v0.50 · introduced in Arma 2 v1.00*

## Description

Execute scripted FSM and return the FSM handle or 0 when failed. The FSM file is first searched in the mission folder, then in the campaign scripts folder and finally in the global scripts folder. Argument (if any) are available in `_this` variable inside FSM. Variables set inside FSMs can be read/modified externally, using [setFSMVariable](../commands/setFSMVariable.md) and [getFSMVariable](../commands/getFSMVariable.md) commands.

The return value is the FSM handle; it can be used to determine (via [completedFSM](../commands/completedFSM.md)) when the FSM has finished.

> [!NOTE]
> **Arma 3:** In Arma 3, the FSM handle is also available within the FSM through the `_thisFSM` variable.

Scripted FSMs are added into the scheduler just like [exec](../commands/exec.md) scripts, [execVM](../commands/execVM.md) scripts and [spawn](../commands/spawn.md) scripts.

To see what FSMs are currently in the scheduler, use [diag_activeMissionFSMs](../commands/diag_activeMissionFSMs.md) command.

> [!IMPORTANT]
> While the code placed into any of the sections of FSM cannot be suspended ([canSuspend](../commands/canSuspend.md) is false), the FSM itself is suspended every simulation between the state's `init` and `precondition` (exception is the **init state**). This is the only place where scripted FSM is suspended/resumed.
> The usual difference between the state's `init` and `precondition` is 1 frame but if the scheduler is busy it can take longer. See FSM for more information about FSM's structure.

## Syntax

### Syntax 1

```sqf
arguments execFSM fsmFilePath
```

**Parameters:**

- `arguments`: [Anything](../topics/Anything.md) - arguments accessible as `_this` in the FSM
- `fsmFilePath`: [String](../topics/String.md) - file with FSM code

**Returns:** [Number](../topics/Number.md) - FSM handle (also available as `_thisFSM` in the FSM)

### Syntax 2

```sqf
execFSM fsmFilePath
```

**Parameters:**

- `fsmFilePath`: [String](../topics/String.md) - file with FSM code

**Returns:** [Number](../topics/Number.md) - FSM handle (also available as `_thisFSM` in the FSM)

### Syntax 3

*since arma3 2.18*

```sqf
arguments execFSM [fsmFilePath, allowTermination]
```

**Parameters:**

- `arguments`: [Anything](../topics/Anything.md) - arguments accessible as `_this` in the FSM
- `fsmFilePath`: [String](../topics/String.md) - file with FSM code
- `allowTermination`: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) to allow FSM termination with [terminate](../commands/terminate.md) command. Optional, default [false](../commands/false.md)

**Returns:** [Number](../topics/Number.md) - FSM handle (also available as `_thisFSM` in the FSM)

### Syntax 4

*since arma3 2.18*

```sqf
execFSM [fsmFilePath, allowTermination]
```

**Parameters:**

- `fsmFilePath`: [String](../topics/String.md) - file with FSM code
- `allowTermination`: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) to allow FSM termination with [terminate](../commands/terminate.md) command. Optional, default [false](../commands/false.md)

**Returns:** [Number](../topics/Number.md) - FSM handle (also available as `_thisFSM` in the FSM)

## Examples

### Example 1

```sqf
_id = player execFSM "test.fsm";
```

### Example 2

```sqf
_handle = [_a, _b, _c] execFSM "test.fsm";
```

### Example 3

```sqf
_handle = execFSM "test.fsm";
```

## See also

FSM · FSM Editor Manual · [execVM](../commands/execVM.md) · [call](../commands/call.md) · [spawn](../commands/spawn.md) · [exec](../commands/exec.md) · [commandFSM](../commands/commandFSM.md) · [completedFSM](../commands/completedFSM.md) · [doFSM](../commands/doFSM.md) · [getFSMVariable](../commands/getFSMVariable.md) · [setFSMVariable](../commands/setFSMVariable.md)

<sub>Source: [BI Community Wiki — execFSM](https://community.bistudio.com/wiki/execFSM) (revision 363581).</sub>
