---
name: "Arma 3: Functions Library"
type: topic
aliases: ["Arma 3 Functions Library", "CfgFunctions", "Functions Library (Arma 3)"]
source: https://community.bistudio.com/wiki/Arma_3:_Functions_Library
revid: 379070
updated: 2026-09-25T10:49:19Z
---

# Arma 3: Functions Library

Arma 3's **Functions Library** is the way to declare mission, campaign or addon's Functions. The main difference from older Function Libraries is that it runs automatically and does not require a Functions module.

The advantages of using the Functions Library over e.g [execVM](../commands/execVM.md) an [SQF](../topics/SQF_Syntax.md) file are as follow:
1. **Automatic compilation upon mission start** into a global variable - no need to remember direct paths to files.
1. **Anti-hack protection** using [compileFinal](../commands/compileFinal.md) (see [Arma 3: Writing a Function#Recompiling](../topics/Writing_a_Function.md#recompiling) and [BIS_fnc_recompile](../functions/BIS_fnc_recompile.md))
1. **Listing in the Functions Viewer**
1. **Advanced debugging options**
1. **Optional immediate execution upon mission start**, without need for manual call
1. **Potential performance improvements**

> [!IMPORTANT]
> This page is about Arma 3 Functions Library.
> - For Arma 2/Arma 2:OA, see Arma 2: Functions Library.
> - For Take On Helicopters, see Take On Helicopters: Functions Library.

### Function Declaration

Functions are configured within the `CfgFunctions` class.

Mission and campaign specific functions can be configured in [Description.ext](../topics/Description.ext.md)/Campaign Description.ext, while addon functions are defined in Config.cpp.
Configuration structure is the same in both cases.

> [!NOTE]
> The root directory (noted as **<ROOT>** on this page) is the origin from which the game will try to load function files. It depends on `CfgFunctions`' location:
> - if [Description.ext](../topics/Description.ext.md), **<ROOT>** means the mission's root directory
> - if Campaign Description.ext, **<ROOT>** means the campaign's root directory
> - if in config, **<ROOT>** means the **game**'s root directory. The addon path needs to be set manually.

See a basic example config:
 class **CfgFunctions**
 {
 	class TAG
 	{
 		class Category
 		{
 			class functionName {};
 		};
 	};
 };
- The function's name will be **TAG**_fnc_**functionName**
- The function will be loaded:
  - from config: `**<ROOT>**\Category\**fn_**functionName**.sqf**`
  - from description.ext: `**<ROOT>**\**functions**\Category\**fn_**functionName**.sqf**`

> [!IMPORTANT]
> **config.cpp only**:
> - `<ROOT>` in mods is defined by the `file` mandatory attribute - see the [#file](../topics/Functions_Library.md#file) section below.
> - Anywhere outside of running mission, refer to the functions stored in [uiNamespace](../commands/uiNamespace.md). e.g: 
>
> ```sqf
> arguments call (uiNamespace getVariable "TAG_fnc_functionName");
> ```

#### Config Levels

A **CfgFunctions** config is made of three levels: Tag, Category, and Function.

##### Tag

To prevent duplicates, every author must create a subclass with a unique tag and create functions under it.
The tag name will be used when composing a function name (e.g [**BIS**_fnc_spawnGroup](../functions/BIS_fnc_spawnGroup.md)).
 class CfgFunctions
 {
 	class TAG
 	{
 		class Category
 		{
 			class myFunction {};
 		};
 	};

 	class TAG_WeaponManagement
 	{
 		**tag** = "TAG"; `// the function will be named **TAG_fnc_myOtherFunction**`
 		class Category
 		{
 			class myOtherFunction {};
 		};
 	};
 };

###### Attributes

###### tag

The `tag` attribute can override the config tag set differently.

##### Category

The category name changes the function's category in the Functions Viewer. It does not change the function's name, only the loading path.
 class CfgFunctions
 {
 	class TAG
 	{
 		class Category
 		{
 			class myFunction {};
 		};

 		class OtherCategory
 		{
 			**file** = "My\Category\Path";
 			class myFunction {}; `// file path will be **<ROOT>**\My\Category\Path\fn_myFunction.sqf";`
 		};

 		class DataCategory
 		{
 			**requiredAddons[]** = { "A3_Data_F" }; `// Optional requirements of CfgPatches classes. If some addons are missing, category functions will not be compiled.`
 			class myDataFunction {};
 		};
 	};
 };

###### Attributes

###### file

The `file` attribute can override the category's loading path segment - it is required for mods.

###### requiredAddons

The category can skip loading if a required addon is missing by setting its dependency with the `requiredAddons` attribute.

##### Function

> [!NOTE]
> By convention, the function class should be named in **camelCase** and not have its first letter capitalised (e.g PascalCase):
> - ✓ TAG_fnc_myFunction
> - ✗ TAG_fnc_MyFunction
> - ✓ TAG_fnc_POWRescue

 class CfgFunctions
 {
 	class TAG
 	{
 		class Category1
 		{
 			class myFunction {};
 		};

 		class Category2
 		{
 			file = "Path\To\Category";
 			class myFunction
 			{
 				**file** = "My\Function\Filepath.sqf"; `// file path will be **<ROOT>**\My\Function\Filepath.sqf", ignoring "Path\To\Category"`
 			};

 			class myFSMFunction
 			{
 				**preInit**		= 1;
 				**postInit**	= 1;
 				**ext**			= ".fsm";
 				**preStart**	= 1;
 				**recompile**	= 1;
 			};
 		};
 	};
 };

###### Attributes

| Attribute | Description | Available in |  |
|---|---|---|---|
| [Description.ext](../topics/Description.ext.md) | config.cpp |  |  |
| file | the `file` attribute can be used to manually set the file path.<br>> [!IMPORTANT]<br>> The **file** entry **overrides** Category's set path and ignores it entirely (they are not merged). | ✓ | ✓ |
| preInit | the `preInit` attribute (formerly known as "forced") can be set to 1 to call the function upon mission start, before objects are initialized.<br>Passed arguments are `["preInit"]`.<br>The function is run in an **[unscheduled environment](../topics/Scheduler.md#unscheduled-environment)**. | ✓ | ✓ |
| postInit | the `postInit` attribute can be set to 1 to call the function upon mission start, after objects are initialized.<br>Passed arguments are `["postInit", didJIP]`.<br>The function is run in a **[scheduled environment](../topics/Scheduler.md#scheduled-environment)** so suspension is allowed, but **any long term suspension will halt the mission loading until suspension is done**. | ✓ | ✓ |
| ext | the `ext` attribute can be used to set function file's type; it can be one of:<br>- ".sqf" (default)<br>- ".fsm" (see FSM) | ✓ | ✓ |
| preStart | the `preStart` attribute can be set to 1 to call the function upon game start, before title screen, but after all addons are loaded. | ✗ | ✓ |
| recompile | the `recompile` attribute can be set to 1 to recompile the function upon mission start (functions in [Description.ext](../topics/Description.ext.md) are always compiled upon mission (re)start) | ✗ | ✓ |
| headerType | the `headerType` adds code to the beginning of functions that can:<br>- Set up the [Meta Variables](../topics/Functions_Library.md#meta-variables) _fnc_scriptParent and _fnc_scriptName<br>- Name the current scope via the command [scriptName](../commands/scriptName.md)<br>- Adds debug information by saving the current execution order in the [Array](../topics/Array.md) _fnc_scriptMap.<br>Possible values are:<br>- -1: No header - Adds nothing, literally adds a blank [String](../topics/String.md) to the beginning of functions. The functions will have no debug or [#Meta Variables](../topics/Functions_Library.md#meta-variables) assigned for it and the scope will not be named. Useful to reduce the performance overhead or if custom debug system is used.<br>- 0: Default header - The default header changes based on the current [Debug Mode](../topics/Functions_Library.md#debug-modes)<br>- 1: System header - Incorporates the [Meta Variables](../topics/Functions_Library.md#meta-variables) _fnc_scriptParent. Also names the current scope.<br>```sqf<br>private _fnc_scriptNameParent = if (isNil '_fnc_scriptName') then { '%1' } else { _fnc_scriptName };<br>scriptName '%1';<br>```<br>See the following section for more information. | ✓ | ✓ |

> [!IMPORTANT]
> Notes about `preInit` and `postInit` defined in **config.cpp**:
> - these attributes will make the function run **on each, every and any mission start**
> - Any scripting error will prevent the mission from being loaded correctly
> - Server admins might blacklist the whole addon if they find out the function is used for hacking

### Advanced Knowledge

#### Meta Variables

- **_fnc_scriptName**: [String](../topics/String.md) - Name of the script
- **_fnc_scriptNameParent**: [String](../topics/String.md) - Name of the parent script
- **_fnc_scriptMap**: [Array](../topics/Array.md) - List of all parent scripts

#### Debug Modes

Developers can access several debug modes using *[BIS_fnc_functionsDebug](../functions/BIS_fnc_functionsDebug.md)* function. **For this to work [function recompiling](../topics/Description.ext.md#allowfunctionsrecompile) has to be allowed!**

##### Debug Mode 0

default - incorporates the [Meta Variables](../topics/Functions_Library.md#meta-variables) _fnc_scriptParent and _fnc_scriptName and names the current scope.

```sqf
private _fnc_scriptNameParent = if (isNil "_fnc_scriptName") then { "%1" } else { _fnc_scriptName };
private _fnc_scriptName = "%1";
scriptName _fnc_scriptName;
```

##### Debug Mode 1

As per *Debug Mode 0* and also saves the current execution order in the [Array](../topics/Array.md) _fnc_scriptMap.

```sqf
private _fnc_scriptNameParent = if (isNil "_fnc_scriptName") then { "%1" } else { _fnc_scriptName };
private _fnc_scriptName = "%1";
scriptName _fnc_scriptName;
private _fnc_scriptMap = if (isNil "_fnc_scriptMap") then { [_fnc_scriptName] } else { _fnc_scriptMap + [_fnc_scriptName] };
```

##### Debug Mode 2

As per *Debug Mode 1* and also outputs execution order using [textLogFormat](../commands/textLogFormat.md) ( textLogFormat is not available in the retail version of Arma3 ) is it available in Diagnostics exe?

```sqf
private _fnc_scriptNameParent = if (isNil "_fnc_scriptName") then { "%1" } else { _fnc_scriptName };
private _fnc_scriptName = "%1";
scriptName _fnc_scriptName;
private _fnc_scriptMap = if (isNil "_fnc_scriptMap") then { [_fnc_scriptName] } else { _fnc_scriptMap + [_fnc_scriptName] };
textLogFormat ["%1 : %2", _fnc_scriptMap joinString " >> ", _this];
```

### See Also

- [Initialisation Order](../topics/Initialisation_Order.md)
- Arma 3: Functions Viewer
- Arma 3 Functions
- [Writing a Function Tutorial](../topics/Writing_a_Function.md)

Arma 3 Editing

<sub>Source: [BI Community Wiki — Arma 3: Functions Library](https://community.bistudio.com/wiki/Arma_3:_Functions_Library) (revision 379070).</sub>
