{"name":"compileFinal","operator":null,"title":"compileFinal","type":"command","url":"https://community.bistudio.com/wiki/compileFinal","revid":378946,"updated":"2026-08-29T21:45:18Z","groups":["Strings"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"0.56"}],"since":{"game":"arma3","name":"Arma 3","version":"0.56"},"arma3_since":"0.56","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"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","since":null,"effect":null,"exec":null,"params":[{"name":"expression","type":"String, Arma 3 v2.14 Code or HashMap","optional":false,"default":null,"description":null,"types":["String","Code","HashMap"],"since":null,"text":"expression: String, Arma 3 v2.14 Code or HashMap"}],"returns":{"type":"Code or HashMap","types":["Code","HashMap"],"description":null,"text":"Code or HashMap"},"form":"unary","operator":null,"left":null,"right":{"text":"expression","types":["String","Code","HashMap"]}}],"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\";"]},{"text":"```sqf\n// 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;\n```","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;"]},{"text":"```sqf\n// since Arma 3 v2.14\nReadonlyCode = compileFinal { systemChat \"Hello World!\"; };\nReadonlyHashMap = compileFinal _myHashMap;\n```","code":["// since Arma 3 v2.14\nReadonlyCode = compileFinal { systemChat \"Hello World!\"; };\nReadonlyHashMap = compileFinal _myHashMap;"]}],"multiplayer":null,"problems":null,"aliases":[],"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```"}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Strings","Introduced with Arma 3 version 0.56","Scripting Commands"]}