---
name: "Introduction to Arma Scripting"
type: topic
aliases: ["ArmA: Armed Assault: Introduction to Scripting", "ArmA: Introduction to Scripting", "Scripting"]
source: https://community.bistudio.com/wiki/Introduction_to_Arma_Scripting
revid: 371144
updated: 2025-02-28T17:08:27Z
---

# Introduction to Arma Scripting

Scripting is one of the most powerful and most versatile tools available in the Arma sandbox. Unfortunately, it is also one of the most complex and unforgiving aspects of addon (i.e. mod) and mission creation.

All Arma games from Arma: Cold War Assault to Arma 3 use a scripting language called [SQF](../topics/SQF_Syntax.md). Its predecessor [SQS](../topics/SQS_Syntax.md) has been considered deprecated since Armed Assault (2006) and is no longer used.
As of Arma Reforger (2022), SQF has been succeeded by Enforce Script. This document only considers SQF.

### Scripting Topics

There is a plethora of topics to learn about in the context of Arma scripting (see the table below).
Fortunately, there is no need to acquire detailed knowledge about all of these things in order to get started with scripting.
To aid with prioritisation, this page provides three selections of topics, each relevant to beginner, intermediate and advanced scripters respectively.

| Real Virtuality Scripting |  |  |
|---|---|---|
| Terminology |  | [Argument](../topics/Argument.md) ● [Identifier](../topics/Identifier.md) ● [Expression](../topics/Expression.md) ● [Operand](../topics/Operand.md) ● [Operators](../topics/Operators.md) ● [Parameter](../topics/Parameter.md) ● [Statement](../topics/Statement.md) ● [Variables](../topics/Variables.md) ● [Magic Variables](../topics/Magic_Variables.md) ● [Function](../topics/Function.md) |
| Syntax |  | [SQF Syntax](../topics/SQF_Syntax.md) ● [SQS Syntax](../topics/SQS_Syntax.md) ● [Order of Precedence](../topics/Order_of_Precedence.md) ● [Control Structures](../topics/Control_Structures.md) |
| Tutorials |  | [Introduction to Arma Scripting](../topics/Introduction_to_Arma_Scripting.md) ● [Code Best Practices](../topics/Code_Best_Practices.md) ● Example Code ● [Code Optimisation](../topics/Code_Optimisation.md) ● [Mission Optimisation](../topics/Mission_Optimisation.md) ● [Multiplayer Scripting](../topics/Multiplayer_Scripting.md) ● [SQS → SQF](../topics/SQS_to_SQF_conversion.md) |
| Data Types | General | [Array](../topics/Array.md) ● [Boolean](../topics/Boolean.md) ● [Code](../topics/Code.md) ● [Config](../topics/Config.md) ● [Control](../topics/Control.md) ● [Diary Record](../topics/Diary_Record.md) ● [Display](../topics/Display.md) ● [Eden Entity](../topics/Eden_Entity.md) ● [Eden ID](../topics/Eden_ID.md) ● [Editor Object](../topics/Editor_Object.md) ● [Group](../topics/Group.md) ● [HashMap](../topics/HashMap.md) ● [Location](../topics/Location.md) ● [Namespace](../topics/Namespace.md) ● [Number](../topics/Number.md) ● [Object](../topics/Object.md) ● [Script Handle](../topics/Script_Handle.md) <br>[Side](../topics/Side.md) ● [String](../topics/String.md) ● [Structured Text](../topics/Structured_Text.md) ● [Task](../topics/Task.md) ● [Team](../topics/Team.md) ● [Team Member](../topics/Team_Member.md) ● [NaN](../topics/NaN.md) ● [Anything](../topics/Anything.md) ● [Nothing](../topics/Nothing.md) ● [Void](../topics/Void.md) ● [Switch Type](../topics/Switch_Type.md) ● [While Type](../topics/While_Type.md) ● [With Type](../topics/With_Type.md) ● [For Type](../topics/For_Type.md) ● [If Type](../topics/If_Type.md) |
| Data Types | Special Arrays | [Array of Eden Entities](../topics/Array_of_Eden_Entities.md) ● [Color](../topics/Color.md) ● [Date](../topics/Date.md) ● [ParticleArray](../topics/ParticleArray.md) ● [Position](../topics/Position.md) ● [Unit Loadout Array](../topics/Unit_Loadout_Array.md) ● [Vector3D](../topics/Vector3D.md) ● [Waypoint](../topics/Waypoint.md) |
| Scripting Commands |  | Scripting Commands ● Scripting Commands by Functionality |
| Scripting Functions |  | Scripting Functions ● Functions by Functionality |
| Debugging |  | Common Scripting Errors ● [Debugging Techniques](../topics/Debugging_Techniques.md) ● [Exception handling](../topics/Exception_handling.md) |
| Advanced |  | [Event Scripts](../topics/Event_Scripts.md) ● Event Handlers ● [PreProcessor Commands](../topics/PreProcessor_Commands.md) ● [Initialisation Order](../topics/Initialisation_Order.md) ● [Performance Profiling](../topics/Performance_Profiling.md) |

### Beginner Scripting

#### Variables

[Variables](../topics/Variables.md) are a fundamental building block of scripting (and programming in general). Like in mathematics, they serve as placeholders for values. A few examples:

- `A = 1;` The variable `A` now has the value 1.
- `B = 2;` The variable `B` now has the value 2.
- `C = "Hello World!";` The variable `C` now has the value "Hello World!".

A variable always has a Data Type. In the example above, the variables `A` and `B` both have the data type [Number](../topics/Number.md), while `C` has the data type [String](../topics/String.md). The data type of a variable is not fixed and changes automatically based on the current value of the variable.

#### Commands and Operators

Two other basic tools of scripting are commands and [Operators](../topics/Operators.md). In fact, they are so basic that the examples in the [Variables](../topics/Introduction_to_Arma_Scripting.md#variables) section above already had to make use of an operator: The equals sign (`=`) serves as the assignment operator, assigning values to variables. Similarly, symbols such as `+`, `-`, `*` and `/` are also operators. Using operators is quite simple:

```sqf
A = 1.5;
B = -2 * A;
C = A + B + 3.5; // Result: C is 2
```

Commands are often more versatile and complex than operators and can sometimes be used to interact with the game in some way. For instance, the [setPosATL](../commands/setPosATL.md) command can be used to change the position of an object in the game world, the [damage](../commands/damage.md) command returns the amount of damage an object has suffered and the [systemChat](../commands/systemChat.md) command can be used to display a message in the system chat.

While operators are usually fairly intuitive to use, commands are often more complicated. As such, every single command (and every single operator) has a dedicated Community Wiki page documenting it. This makes the Community Wiki an essential resource for scripting as it can be consulted whenever an unfamiliar command is encountered or needs to be used. The documentation commonly includes information about the behaviour and effect of the command, its return value and the purpose and data types of its parameters.

> [!NOTE]
> Commands List can be found here: Scripting Commands.

#### Control Structures, Conditions and Booleans

[Control Structures](../topics/Control_Structures.md) allow scripts to accomplish complex tasks. See the following:

```sqf
if (damage player > 0.5) then
{
    player setDamage 0;
    systemChat "The player has been healed.";
}
else
{
    systemChat "The player is fine.";
};
```

This code behaves differently depending on the damage status of the player. The [systemChat](../commands/systemChat.md) output and whether or not the player is healed changes dynamically based on how much health the player has when the code is executed.

##### Conditions

In the example above, the condition is `damage player > 0.5`. Like all conditions, it results in a [Boolean](../topics/Boolean.md) value when evaluated:

1. First, `damage player` is evaluated and returns a number.
1. Then, the `>` operator compares that number to 0.5:
   - If the number is greater than 0.5, the `>` operator returns [true](../commands/true.md).
   - If the number is less than or equal to 0.5, the `>` operator returns [false](../commands/false.md).

##### Booleans

The data type [Boolean](../topics/Boolean.md) only has two possible values: [true](../commands/true.md) and [false](../commands/false.md).

###### Boolean Operations

There are three basic operations that can be performed on Boolean values:

| Operation | Description | SQF Operator | SQF Command |
|---|---|---|---|
| NOT (Negation) | Inverts the input value. | `!` | [not](../commands/not.md) |
| AND (Conjunction) | Combines two Booleans into one. Only returns [true](../commands/true.md) if both input values are [true](../commands/true.md). | `&&` | [and](../commands/and.md) |
| OR (Disjunction) | Combines two Booleans into one. Returns [true](../commands/true.md) if at least one of the input values is [true](../commands/true.md). | `\|\|` | [or](../commands/or.md) |

Both the input and the output of these operations are Boolean values. Their behaviour is defined as follows:

|  |  |  |
|---|---|---|
| \| NOT \|  \|<br>\|---\|---\|<br>\| Expression \| Result \|<br>\| `!true` \| [false](../commands/false.md) \|<br>\| `!false` \| [true](../commands/true.md) \| | \| AND \|  \|<br>\|---\|---\|<br>\| Expression \| Result \|<br>\| `true && true` \| [true](../commands/true.md) \|<br>\| `true && false` \| [false](../commands/false.md) \|<br>\| `false && true` \| [false](../commands/false.md) \|<br>\| `false && false` \| [false](../commands/false.md) \| | \| OR \|  \|<br>\|---\|---\|<br>\| Expression \| Result \|<br>\| `true \\|\\| true` \| [true](../commands/true.md) \|<br>\| `true \\|\\| false` \| [true](../commands/true.md) \|<br>\| `false \\|\\| true` \| [true](../commands/true.md) \|<br>\| `false \\|\\| false` \| [false](../commands/false.md) \| |

##### Complex Conditions

Boolean operations can be used to create complex conditions by combining multiple conditions into one.

```sqf
if ((alive VIP_1 && triggerActivated VIP_1_Task_Complete) || (alive VIP_2 && triggerActivated VIP_2_Task_Complete)) then
{
    systemChat "At least one VIP has been rescued.";
};
```

> [!NOTE]
> Beginners sometimes write conditions such as `if (Condition == true)` or `if (Condition == false)`.
>
> While doing so is not a real error, it is unnecessary because [Control Structures](../topics/Control_Structures.md) (and Triggers) always implicitly compare the condition to [true](../commands/true.md).
>
> The correct (as in faster, more common and more readable) way to write such conditions is `if (Condition)` and `if (!Condition)` respectively.

#### Arrays

An [Array](../topics/Array.md) is a Data Type that can be seen as a list of items. This list can hold none to multiple elements of different types:

```sqf
[]                        // an empty array
[true]                    // an array of 1 element (Boolean)
[0, 10, 20, 30, 40, 50]    // an array of 6 elements of Number type
["John Doe", 32, true]    // an array of 3 elements of different types (String, Number, Boolean)
```

An array is a useful way to keep data together and is used for example to store positions.

##### Positions

[Positions](../topics/Position.md) are represented as 2D or 3D [Arrays](../topics/Array.md) of [Numbers](../topics/Number.md) (usually in the format `[X, Y]` or `[X, Y, Z]`) where X represents West-East, Y represents South-North and Z represents altitude.
However, there are some important caveats and distinctions one should be aware of - for instance, the positions `[0, 0, 0]` ASL (**A**bove **S**ea **L**evel) and `[0, 0, 0]` AGL (**A**bove **G**round **L**evel) are not necessarily equivalent.
It is therefore highly recommended to read the [Positions](../topics/Position.md) page before working with positions.

#### Script Files

Scripts are usually placed in [Script Files](../topics/Script_File.md). It is of course possible and sometimes even necessary to use short pieces of code in the Editor (e.g. in the *On Activation* expression of a Trigger), but scripts can become long and complex, and then working with them is far easier when they are properly placed in script files. Additionally, some features are only accessible through the use of script files ([Event Scripts](../topics/Event_Scripts.md) for example).

Script files are basically just text files with a certain filename extension. For script files, that file extension is `.sqf` (or `.sqs`), but in the broader context of Arma scripting, modification, configuration and mission design, more file extensions can be encountered: `.ext`, `.hpp`, `.cpp` and `.cfg` to mention the most common ones.

##### File Creation

Unfortunately, Windows does not make the creation of blank files with a desired file extension easily accessible.

For instance, a common pitfall when trying to use [Description.ext](../topics/Description.ext.md) (a file that is used to configure certain mission features such as the respawn settings) for the first time is (unknowingly) creating `Description.ext.txt` instead of `Description.ext` because the Windows File Explorer hides file extensions by default.
Obviously, `Description.ext.txt` will not work and will not have any of the desired effects on the mission because the game does not recognize it as `Description.ext`, but identifying a wrong file extension as the root cause of an issue when troubleshooting is notoriously difficult as one is usually looking for errors in the code and not in the filename.

While there are many different ways to create a blank text file with a specific file extension, the easiest method using native Windows tools is probably this:

- Preparation (only needs to be done once):

1. Open the File Explorer
1. Open the *View* tab at the top
1. Tick the *File name extensions* checkbox

- File Creation:

1. Navigate to the location where you want to create a new script file
1. Right-click
1. Go to *New*
1. Click on *Text Document*
1. Rename `New Text Document.txt` to what you need

> [!NOTE]
> It is also possible to bypass Notepad's automatic addition of the `.txt` extension by wrapping the file name in quote, e.g `"description.ext"`.

##### File Locations

In the context of mission creation, script files generally need to be placed in the corresponding *scenario folder* (often also called the *mission root folder*). Every mission has its own scenario folder, it is created by the Editor when saving the scenario for the first time.
By default it only contains a single file called [`mission.sqm`](../topics/Mission.sqm.md); this file mostly stores data regarding Editor-placed entities and does not need to be touched when scripting.

[Description.ext](../topics/Description.ext.md) and [Event Scripts](../topics/Event_Scripts.md) have to be placed directly in the root of the scenario folder (i.e. next to `mission.sqm`), but all other files can be placed in subfolders of the scenario folder.
A well-structured scenario folder could look like this:

```
Apex%20Protocol.Tanoa/
├── functions/
│   ├── fn_myFirstFunction.sqf
│   └── fn_mySecondFunction.sqf
├── scripts/
│   ├── myFirstScript.sqf
│   └── mySecondScript.sqf
├── description.ext
├── initPlayerLocal.sqf
├── initServer.sqf
└── mission.sqm
```

Each scenario folder is stored in either the `missions` or the `mpmissions` subfolder of the folder containing the [Arma Profile](../topics/Profile.md) that was used to create the scenario.
For instance, the path to the scenario folder from the example above could be:

```
C:\Users\Scott Miller\Documents\Arma 3 - Other Profiles\Keystone\missions\Apex%20Protocol.Tanoa
```

The Editor uses [percent-encoding](https://en.wikipedia.org/wiki/Percent-encoding) for scenario folder names, that is why whitespaces in the scenario name are replaced with `%20`.

> [!NOTE]
> The Eden Editor provides a useful shortcut to quickly open a mission's scenario folder in the Windows File Explorer:
> With the mission open in the Editor, go to *Scenario* in the top left and then click on *Open Scenario Folder*.

**See Also:**

- [2D Editor: External](../topics/2D_Editor~3A_External.md)
- [Eden Editor: Scenario Folder](../topics/Eden_Editor~3A_Scenario_Folder.md)
- [Profile](../topics/Profile.md) (the possible profile folder paths are listed there)

##### Editing Script Files

Because script files are essentially plain text files, they can be edited with just about any text editor. For instance, the native Windows Notepad can be used, but working with it is not very comfortable. As such, regular scripters typically use more versatile applications such as [Notepad++](https://notepad-plus-plus.org) or [Visual Studio Code](https://code.visualstudio.com), usually in combination with plugins that add additional support for SQF. One feature commonly provided by these plugins is *syntax highlighting*, and for good reason: Syntax highlighting makes code significantly more readable and helps recognizing and avoiding basic syntax errors. Consequently, it is highly recommended to use syntax highlighting.

See Community Tools - Code Edition for a selection of community-made applications and plugins for Arma Scripting.

##### Script Execution

The [execVM](../commands/execVM.md) command is used to execute script files.

For instance, `myFirstScript.sqf` from the [File Locations](../topics/Introduction_to_Arma_Scripting.md#file-locations) example above can simply be executed like so:

```sqf
execVM "scripts\myFirstScript.sqf";
```

This can be done anywhere: Within another script, from the [Debug Console](../topics/Debug_Console.md), in the *On Activation* or *On Deactivation* expression of a Trigger or in the init field of an [Object](../topics/Eden_Editor~3A_Object.md) in the Editor.

### Intermediate Scripting

### Advanced Scripting

### Miscellaneous

> [!NOTE]
> This section contains content from an old version of this page which is due to be updated.

### Before anything

**Is your idea necessary?** Will players even notice or use what you want to script? Just because you can does not mean you should. Sometimes less is more!

**Is it possible to do this in the editor?** The Eden Editor is a powerful tool and with it alone one can achieve a lot of things without writing a single line of code.

Poorly written scripts are a frequent cause of poor performance, both in singleplayer and multiplayer scenarios.

**Can it be scripted using SQF?** This question might be hard to answer. Try to get as much information about what you want to do and what commands and functions there are before spending time on writing a script, just to find out that what you hoped to achieve is not possible after all.

> [!NOTE]
> Scripting is not the solution for everything!

#### Terms

The following is a collection of terms frequently encountered when talking or reading about scripting.

**Game Engine:** The core program of the game which executes your scripting commands at run time.

**Script / Script File:** Scripts are usually placed in [script files](../topics/Script_File.md). Script files contain code.

**Syntax:** See [SQF Syntax](../topics/SQF_Syntax.md) (Arma, Arma 2, Arma 3).

See [SQS Syntax](../topics/SQS_Syntax.md) (Operation Flashpoint, Arma).

**Variables:** A [Variable](../topics/Variables.md) is a named storage container for data.

The name of a variable is called its [Identifier](../topics/Identifier.md).

**Data Types:** The Data Type of a variable specifies which kind of data that variable can contain.

**Operators:** See [Operators](../topics/Operators.md)

**Control Structures:** See [Control Structures](../topics/Control_Structures.md)

**Functions:** See [Function](../topics/Function.md)

#### Must-Read Articles

##### Best Practices

See [Code Best Practices](../topics/Code_Best_Practices.md)

##### Debugging

- [Debugging Techniques](../topics/Debugging_Techniques.md)
- Community Tools - Debug Console/System

##### Optimisation

- [Code Optimisation](../topics/Code_Optimisation.md)
- [Mission Optimisation](../topics/Mission_Optimisation.md)

#### Useful Links

These pages cover further aspects of scripting:

- Example Code
- [Control Structures](../topics/Control_Structures.md)
- [Multiplayer Scripting](../topics/Multiplayer_Scripting.md)
- [Exception handling](../topics/Exception_handling.md)
- [Script File](../topics/Script_File.md)
- [Function](../topics/Function.md)
- [SQS to SQF conversion](../topics/SQS_to_SQF_conversion.md)

Consider the following resources for more general learning:

- 6thSense.eu Editing Guide
- *Fockers Arma 3 Scripting Guide* (dead link)
- *Mr-Murray's Armed Assault Editing Guide - Deluxe Edition* (dead link)
- [Excellent German SQF tutorial (YouTube)](https://youtu.be/WmEBN-RbK44)

<sub>Source: [BI Community Wiki — Introduction to Arma Scripting](https://community.bistudio.com/wiki/Introduction_to_Arma_Scripting) (revision 371144).</sub>
