compileFinal: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Some wiki formatting) |
Lou Montana (talk | contribs) m (Text replacement - "Nelis.75733126" to "Nelis75733126") |
||
(8 intermediate revisions by 3 users not shown) | |||
Line 6: | Line 6: | ||
|gr1= Strings | |gr1= Strings | ||
|descr= Compiles an expression and makes it final, preventing it from | |descr= 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). | ||
{{Feature|informative|This feature is only available in the retail version of {{arma3}}.}} | {{Feature|informative|This feature is only available in the retail version of {{arma3}}.}} | ||
|s1= [[compileFinal]] expression | |s1= [[compileFinal]] expression | ||
|p1= expression: [[String]] | |p1= expression: [[String]], {{GVI|arma3|2.14|size= 0.75}} [[Code]] or [[HashMap]] | ||
|r1= [[Code]] | |r1= [[Code]] or [[HashMap]] | ||
|x1= <sqf> | |x1= <sqf> | ||
_myCode = compileFinal "a = a + 1"; | |||
call | call _myCode; | ||
// | // repeated compile won't have any effect | ||
_myCode = compileFinal "a = a + 2"; | |||
</sqf> | |||
|x2= <sqf> | |||
// duplicate code will be final as well | |||
_myDuplicateCode = _myCode; | |||
// | // an alternative is to copy str'd code (since Arma 3 v2.02) | ||
private _myNonFinalCopy = compile toString _myCode; | |||
</sqf> | </sqf> | ||
| | |x3= <sqf> | ||
// since {{arma3}} v2.14 | |||
private _readonlyCode = compileFinal { systemChat "Hello World!"; }; | |||
private _readonlyHashMap = compileFinal _myHashMap; | |||
</sqf> | </sqf> | ||
Line 46: | Line 48: | ||
{{Note | {{Note | ||
|user= | |user= Nelis75733126 | ||
|timestamp= 20170527115800 | |timestamp= 20170527115800 | ||
|text= in {{arma3}} v1.70.141838, [[compileFinal]] also works for [[profileNamespace]] and [[uiNamespace]]. But be careful with that. | |text= in {{arma3}} v1.70.141838, [[compileFinal]] also works for [[profileNamespace]] and [[uiNamespace]]. But be careful with that. | ||
Line 55: | Line 57: | ||
|timestamp= 20201023103900 | |timestamp= 20201023103900 | ||
|text= Change with {{arma3}} {{Link|https://dev.arma3.com/post/spotrep-00095|patch 2.00}}, [[compileFinal]] is now '''unable''' to store code type variables in [[profileNamespace]]! | |text= Change with {{arma3}} {{Link|https://dev.arma3.com/post/spotrep-00095|patch 2.00}}, [[compileFinal]] is now '''unable''' to store code type variables in [[profileNamespace]]! | ||
}} | |||
{{Note | |||
|user= Hypoxic125 | |||
|timestamp= 20240622234127 | |||
|text= 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 | |||
</sqf> | |||
}} | }} |
Latest revision as of 15:38, 29 June 2024
Description
- 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).
- Groups:
- Strings
Syntax
- Syntax:
- compileFinal expression
- Parameters:
- expression: String, 2.14 Code or HashMap
- Return Value:
- Code or HashMap
Examples
- Example 1:
- Example 2:
- Example 3:
- // since Arma 3 v2.14 private _readonlyCode = compileFinal { systemChat "Hello World!"; }; private _readonlyHashMap = compileFinal _myHashMap;
Additional Information
- See also:
- compile compileScript isFinal call spawn
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
- Posted on Aug 15, 2013 - 00:35 (UTC)
- 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.
- Posted on May 27, 2017 - 11:58 (UTC)
- in Arma 3 v1.70.141838, compileFinal also works for profileNamespace and uiNamespace. But be careful with that.
- Posted on Oct 23, 2020 - 10:39 (UTC)
- Change with Arma 3 patch 2.00, compileFinal is now unable to store code type variables in profileNamespace!
- Posted on Jun 22, 2024 - 23:41 (UTC)
-
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