Arma 3 Scripting

Command in Strings

compileFinal

Also available as Markdown and JSON, or read the original wiki page.

Description

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

Note

This feature is only available in the retail version of Arma 3.

Syntax

compileFinal expression

Parameters:

Returns: Code or HashMap

Examples

Example 1

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

Example 2

// 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

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

See also

compile · compileScript · isFinal · call · spawn

Community notes

AgentRev01

When broadcasting a compileFinal'ed variable using publicVariable 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.

Hypoxic125

Making a base class read only using HashMapObjects

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