---
name: "execVM"
type: command
status: ok
groups: ["Program Flow"]
arma3_since: "0.50"
locality: {"argument": "global", "effect": "local", "server_exec": false}
source: https://community.bistudio.com/wiki/execVM
revid: 336954
updated: 2023-01-04T16:44:15Z
---

# execVM

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

Locality: arguments **global** · effect **local**

## Description

Compiles and adds an [SQF](../topics/SQF_Syntax.md) [script](../topics/Script_Handle.md) to the [scheduler](../topics/Scheduler.md) queue and returns script handle (see also [#Example 4](../commands/execVM.md#example-4)).
The script does not execute immediately upon running [execVM](../commands/execVM.md) command but with some delay depending on the VM's scripts queue and engine load.

> [!NOTE]
> - If the same script is to be executed more than one time, declaring it as a [Function](../topics/Functions_Library.md) is recommended to avoid recompiling and wasting performance with every execution.
> - The script is searched for in the following directories in that order:
>   - mission directory
>   - campaign scripts directory
>   - global scripts directory.
> - To see what VM scripts are currently in the scheduler, use [diag_activeSQFScripts](../commands/diag_activeSQFScripts.md) command.

> [!IMPORTANT]
> - The `.sqf` file extension is not mandatory but is strongly recommended as using non-standard extensions may cause problems during binarisation
> - If the script file is not prepared using UTF-8 encoding and contains some characters [with codes](../commands/toArray.md) > 127, they might convert incorrectly.

## Syntax

### Syntax 1

```sqf
arguments execVM filename
```

**Parameters:**

- `arguments`: [Anything](../topics/Anything.md) - arguments accessible as `_this` in the script
- `filename`: [String](../topics/String.md) - path to the [SQF](../topics/SQF_Syntax.md) script file

**Returns:** [Script Handle](../topics/Script_Handle.md)

### Syntax 2

```sqf
execVM filename
```

**Parameters:**

- `filename`: [String](../topics/String.md) - path to the [SQF](../topics/SQF_Syntax.md) script file

**Returns:** [Script Handle](../topics/Script_Handle.md)

## Examples

### Example 1

```sqf
execVM "test.sqf";
```

### Example 2

```sqf
_handle = player execVM "test.sqf";
waitUntil { scriptDone _handle };
```

The following is also possible in Arma 3:

```sqf
private _handle = execVM "123.sqf";
waitUntil { isNull _handle };
```

### Example 3

```sqf
[player, 0.75] execVM "setDamage.sqf";
```

setDamage.sqf:

```sqf
params ["_unit", "_damage"];
_unit setDamage _damage;
```

### Example 4

[execVM](../commands/execVM.md) equivalence:

```sqf
private _handle = _args execVM "someFile.sqf";
// is practically identical to
private _handle = _args spawn compile preprocessFileLineNumbers "someFile.sqf";
```

## See also

[call](../commands/call.md) · [spawn](../commands/spawn.md) · [exec](../commands/exec.md) · [execFSM](../commands/execFSM.md) · [scriptDone](../commands/scriptDone.md) · [scriptNull](../commands/scriptNull.md) · [terminate](../commands/terminate.md) · [sleep](../commands/sleep.md) · [uiSleep](../commands/uiSleep.md) · [waitUntil](../commands/waitUntil.md) · [canSuspend](../commands/canSuspend.md) · [diag_activeScripts](../commands/diag_activeScripts.md) · [diag_activeSQFScripts](../commands/diag_activeSQFScripts.md) · [SQF Syntax](../topics/SQF_Syntax.md) · [Control Structures](../topics/Control_Structures.md)

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