---
name: "compileFinal"
type: command
status: ok
groups: ["Strings"]
arma3_since: "0.56"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/compileFinal
revid: 378946
updated: 2026-08-29T21:45:18Z
---

# compileFinal

*Command · Strings · Arma 3 v0.56*

## Description

Compiles an expression / takes an existing [HashMap](../topics/HashMap.md) and makes it final, preventing it from being modified or overwritten (by = assignation, [publicVariable](../commands/publicVariable.md), [set](../commands/set.md) or any other command).

> [!NOTE]
> This feature is only available in the retail version of Arma 3.

## Syntax

```sqf
compileFinal expression
```

**Parameters:**

- `expression`: [String](../topics/String.md), Arma 3 v2.14 [Code](../topics/Code.md) or [HashMap](../topics/HashMap.md)

**Returns:** [Code](../topics/Code.md) or [HashMap](../topics/HashMap.md)

## Examples

### Example 1

```sqf
MyCode = compileFinal "a = a + 1";
call MyCode;
 
// repeated compile won't have any effect
MyCode = compileFinal "a = a + 2";
```

### Example 2

```sqf
// duplicate code will be final as well
MyDuplicateCode = MyCode;

// an alternative is to copy str'd code (since Arma 3 v2.02)
MyNonFinalCopy = compile toString MyCode;
```

### Example 3

```sqf
// since Arma 3 v2.14
ReadonlyCode = compileFinal { systemChat "Hello World!"; };
ReadonlyHashMap = compileFinal _myHashMap;
```

## See also

[compile](../commands/compile.md) · [compileScript](../commands/compileScript.md) · [isFinal](../commands/isFinal.md) · [call](../commands/call.md) · [spawn](../commands/spawn.md)

## Community notes

**AgentRev01** — 2013-08-15

When broadcasting a compileFinal'ed variable using [publicVariable](../commands/publicVariable.md) or its variants, the variable also becomes final on the other client(s) and/or the server.
Also, compileFinal does not prevent event handlers from being removed or overwritten.

---

**Nelis75733126** — 2017-05-27

in Arma 3 v1.70.141838, [compileFinal](../commands/compileFinal.md) also works for [profileNamespace](../commands/profileNamespace.md) and [uiNamespace](../commands/uiNamespace.md). But be careful with that.

---

**Hypoxic125** — 2024-06-22

Making a base class read only using HashMapObjects

```sqf
Class_Dog = compileFinal createHashMapObject [
    // Properties
    ["#type", "Dog"],
    ["owner", objNull],
    ["legs", 4],
    ["health", 100],
    ["vehicleclass", "Dog_Base_F"],
    ["vehicle", objNull],

    // Constructor
    ["#create", {
        params [["_owner", objNull], ["_vehicle", objNull]];

        if ([_owner, _vehicle] findIf {isNull _x} != -1) exitWith {};

        _self set ["owner", _owner];
        _self set ["vehicle", _vehicle]
    }]
];

NewDog = createHashMapObject [
    [["#base", Class_Dog]],
    [player_1, createVehicle [Class_Dog get "vehicleclass", [0,0,0], 0, [], "NONE"]]
];

NewDog set ["owner", player_2];
NewDog get "owner";                 // returns player_2

Class_Dog set ["owner", player_1];  // Error: Read Only
```

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