{"name":"compileFinal","title":"compileFinal","type":"command","url":"https://community.bistudio.com/wiki/compileFinal","revid":378946,"updated":"2026-08-29T21:45:18Z","groups":["Strings"],"status":"ok","games":{"arma3":"0.56"},"since":"arma3 0.56","arma3_since":"0.56","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).\n\n> [!NOTE]\n> This feature is only available in the retail version of Arma 3.","syntaxes":[{"syntax":"compileFinal expression","params":[{"name":"expression","type":"String, Arma 3 v2.14 Code or HashMap","type_expr":"String | Code | HashMap"}],"returns":{"type":"Code or HashMap","type_expr":"Code | HashMap"},"form":"unary","right":{"text":"expression"}}],"examples":[{"text":"```sqf\nMyCode = compileFinal \"a = a + 1\";\ncall MyCode;\n\n// repeated compile won't have any effect\nMyCode = compileFinal \"a = a + 2\";\n```","code":["MyCode = compileFinal \"a = a + 1\";\ncall MyCode;\n \n// repeated compile won't have any effect\nMyCode = compileFinal \"a = a + 2\";"]},{"code":["// duplicate code will be final as well\nMyDuplicateCode = MyCode;\n\n// an alternative is to copy str'd code (since Arma 3 v2.02)\nMyNonFinalCopy = compile toString MyCode;"]},{"code":["// since Arma 3 v2.14\nReadonlyCode = compileFinal { systemChat \"Hello World!\"; };\nReadonlyHashMap = compileFinal _myHashMap;"]}],"see_also":["compile","compileScript","isFinal","call","spawn"],"notes":[{"user":"AgentRev01","date":"2013-08-15T00:35:00Z","text":"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.\nAlso, compileFinal does not prevent event handlers from being removed or overwritten."},{"user":"Nelis75733126","date":"2017-05-27T11:58:00Z","text":"in Arma 3 v1.70.141838, compileFinal also works for profileNamespace and uiNamespace. But be careful with that."},{"user":"Hypoxic125","date":"2024-06-22T23:41:27Z","text":"Making a base class read only using HashMapObjects\n\n```sqf\nClass_Dog = compileFinal createHashMapObject [\n    // Properties\n    [\"#type\", \"Dog\"],\n    [\"owner\", objNull],\n    [\"legs\", 4],\n    [\"health\", 100],\n    [\"vehicleclass\", \"Dog_Base_F\"],\n    [\"vehicle\", objNull],\n\n    // Constructor\n    [\"#create\", {\n        params [[\"_owner\", objNull], [\"_vehicle\", objNull]];\n\n        if ([_owner, _vehicle] findIf {isNull _x} != -1) exitWith {};\n\n        _self set [\"owner\", _owner];\n        _self set [\"vehicle\", _vehicle]\n    }]\n];\n\nNewDog = createHashMapObject [\n    [[\"#base\", Class_Dog]],\n    [player_1, createVehicle [Class_Dog get \"vehicleclass\", [0,0,0], 0, [], \"NONE\"]]\n];\n\nNewDog set [\"owner\", player_2];\nNewDog get \"owner\";                 // returns player_2\n\nClass_Dog set [\"owner\", player_1];  // Error: Read Only\n```"}]}