Lou Montana/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
(Array replacement WIP)
m (Update w/ links)
 
(74 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{SideTOC}}
[[Category: Sandbox]]
An '''Array''' is a list of items of varying [[:Category:Types|variable types]]. Different types can coexist within the same array.
{{Feature|informative|To go on [[Initialisation Order]].}}
An Array can be both single-dimension and multi-dimensional.
{{Warning | Since {{arma3}} v1.55.133789 arrays are limited to maximum of '''9,999,999''' (sometimes 10,000,000) elements}}
 
<!--
- map (apply)
- filter (select)
- forEach
- for
--><!--
All can be done with a findIf that exits on first != true.
Any can be done with a findIf that exits on first == true.
Contains is same as Any.
Count we already have.
Where is our select
Select is our apply
reverse we have
OrderBy is on my todo list.
Zip is on my todo list
Union I think is arrayIntersect?
--><!--
// SORTING
sort
BIS_fnc_sortBy
BIS_fnc_sortAlphabetically
BIS_fnc_sortNum
--><!--
1 Working with arrays
1.1 Creating (declaring) arrays
1.2 Multi-dimensional arrays
1.3 Referencing and setting element values
1.4 Adding (appending) to arrays
1.5 Looping to access elements
1.6 Copying
1.7 Subtraction
2 Quirks and errors
2.1 Index rounding
2.2 When an Array index is out of Range
-->
 
 
== Working with arrays ==
 
=== Array properties ===
 
An array variable is a '''pointer''' to the array (see [[https://en.wikipedia.org/wiki/Pointer (computer programming)|Wikipedia pointer page]]);
this means that if the array is edited, all the scripts/functions using a reference to this array will see the edition.
 
[[private]] _myArray = ["a", "b", "c"];
[[private]] _myNewArray = _myArray;
_myArray [[set]] [1, "z"];
_myNewArray [[select]] 1; {{codecomment|// will be "z"}}
 
An array set through [[setVariable]] does not need to be assigned again if you modify it by reference:
[[player]] [[setVariable]] ["myArray", ["a", "b", "c"]];
[[private]] _myArray = [[player]] [[getVariable]] "myArray";
_myArray [[set]] [1, "z"];
[[player]] [[getVariable]] "myArray"; {{codecomment|// is ["a", "z", "c"]}}
 
=== Create an array ===
 
{{codecomment|// Example of an empty array}}
[[private]] _myArray = [];
[[count]] _myArray; {{codecomment|// returns 0}}
{{codecomment|// Correct syntax}}
[[private]] _myFilledArray = ["Weapon1", "Weapon2"];
[[count]] _myFilledArray; {{codecomment|// returns 2}}
 
An array can hold another array within it, that can hold another array itself, etc:
[[private]] _myArray = <nowiki>[["my", "subArray", 1], ["mySubArray2"], [["my", "sub", "sub", "array"]]];</nowiki>
[[count]] &nbsp;&nbsp;_myArray; {{codecomment|// returns 2}}
[[count]] &nbsp;(_myArray [[select]] 0); {{codecomment|// returns 3}}
[[count]] &nbsp;(_myArray [[select]] 1); {{codecomment|// returns 4}}
[[count]] &nbsp;(_myArray [[select]] 2); {{codecomment|// returns 1}}
[[count]] ((_myArray [[select]] 2) [[select]] 0); {{codecomment|// returns 4}}
 
=== Getting an element ===
 
An array uses a zero-based index for its elements:
 
[[private]] _myArray = ["first item", "second item", "third item"];
_myArray [[select]] 0; {{codecomment|// returns "first item"}}
_myArray [[a_hash_b|#]] 2; {{codecomment|// returns "third item" - {{arma3}} only}}
 
=== Setting an element ===
 
[[private]] _myArray = ["first item", "second item", "third item"];
_myArray [[select]] 1; {{codecomment|// returns "second item"}}
_myArray [[set]] [1, "hello there"]; {{codecomment|// _myArray is ["first item", "hello there", "third item"]}}
 
{{Important | If the index given to the [[set]] command is out of bounds, the array will [[resize]] to incorporate the index ''as its last value''.
All the "empty spaces" between the last valid element and the new [[set]] element will be filled with [[nil]]}}
 
=== Counting elements ===
 
[[private]] _myArray = ["first item", "second item", "third item"];
[[count]] _myArray; {{codecomment|// returns 3}}
 
=== Changing array size ===
 
The [[resize]] command is made to reduce or expand an array:
[[private]] _myArray = [1, 2, 3, 4, 5];
_myArray [[resize]] 3; {{codecomment|// _myArray is [1, 2, 3]}}
 
[[private]] _myArray = [1, 2, 3];
_myArray [[resize]] 5; {{codecomment|// _myArray is [1, 2, 3, [[nil]], [[nil]]]}}
 
{{Important | You do '''not''' need to extend an array before adding elements!}}
 
=== Array duplication ===
 
[[private]] _myArray = ["a", "b", "c"];
[[private]] _myNewArray = _myArray;
_myArray [[set]] [1, "z"];
_myNewArray [[select]] 1; {{codecomment|// will be "z"}}
 
[[private]] _myArray = <nowiki>[["a", "b", "c"], ["d", "e", "f"];</nowiki>
[[private]] _subArray1 = _myArray [[select]] 0;
_subArray1 [[set]] [1, "z"];
{{codecomment|// _subArray1 is now ["a", "z", "c"]}}
{{codecomment|// _myArray is now <nowiki>[["a", "z", "c"], ["d", "e", "f"]]</nowiki>}}
 
In order to avoid this behaviour, '''duplicate''' the array with [[+]]:
 
{{codecomment|// duplication}}
[[private]] _myArray = ["a", "b", "c"];
[[private]] _myNewArray = +_myArray;
_myArray [[set]] [1, "z"];
_myNewArray [[select]] 1; {{codecomment|// still "b"}}
 
Sub-arrays are also deep-duplicated; {{Inline code|_myNewArray}} will not point at the same sub-array instances.
 
=== Adding (appending) elements ===
 
In {{arma3}} use [[append]] and [[pushBack]] commands:
 
[[private]] _myArray = [1, 2, 3];
_myArray [[pushBack]] 4; {{codecomment|// _myArray is [1, 2, 3, 4]}}
_myArray [[append]] [5, 6]; {{codecomment|// _myArray is [1, 2, 3, 4, 5, 6]}}
 
 
Before {{arma3}} you had to use [[+]] in order to add a new element:
 
[[private]] _myArray = [1, 2, 3];
_myArray = _myArray + [4]; {{codecomment|// _myArray is [1, 2, 3, 4]}}
_myArray = _myArray + [5, 6]; {{codecomment|// _myArray is [1, 2, 3, 4, 5, 6]}}
 
{{Important | [[append]] and [[pushBack]] have been introduced in {{arma3}} and '''should be used''' for [[Code Optimisation#Adding elements|performance concerns]].}}
 
=== Removing (deleting) elements ===
 
In {{arma3}} use [[deleteAt]] and [[deleteRange]] commands:
 
[[private]] _myArray = [1, 2, 3, 4, 5];
_myArray [[deleteAt]] 0; {{codecomment|// _myArray is [2, 3, 4, 5]}}
_myArray [[deleteRange]] [1, 2]; {{codecomment|// _myArray is [2, 5]}}
 
You can also use [[-]] to remove nested arrays '''in {{arma3}} only''':
 
[[private]] _myArray = <nowiki>[[1, 2, 3], [4, 5, 6], [7, 8, 9]];</nowiki>
_myArray = _myArray - <nowiki>[[4, 5, 6]];</nowiki> {{codecomment|// _myArray is <nowiki>[[1, 2, 3], [7, 8, 9]]</nowiki>}}
 
 
Before {{arma3}} you had to use [[-]] for all these operations:
 
[[private]] _myArray = [1, 2, 3, 4, 5];
_myArray = _myArray - [1]; {{codecomment|// _myArray is [2, 3, 4, 5]}}
 
The issue with this solution is that ''all'' item instances (here, <tt>1</tt>) would be removed:
 
[[private]] _myArray = [1, 2, 1, 2, 1];
_myArray = _myArray - [1]; {{codecomment|// _myArray is [2, 2]}}
 
The solution to this issue is the combined use of [[set]] and an item that you know is '''not''' present in the array:
 
[[private]] _myArray = [1, 2, 1, 2, 1];
_myArray [[set]] [2, [[objNull]]]; {{codecomment|// _myArray is [1, 2, [[objNull]], 2, 1]]}}
_myArray = _myArray - <nowiki>[</nowiki>[[objNull]]]; {{codecomment|// _myArray is [1, 2, 2, 1]]}}
 
Using this technique, it is possible to mimic [[deleteRange]] behaviour this way:
 
[[private]] _myArray = [1, 2, 3, 4, 5];
{ _myArray [[set]] [_x, [[objNull]]] } [[forEach]] [1, 2]; {{codecomment|// _myArray is [1, [[objNull]], [[objNull]], 4, 5]}}
_array = _array - [objNull]; {{codecomment|// _myArray is [1, 4, 5]}}
 
{{Important | [[deleteAt]] and [[deleteRange]] have been introduced in {{arma3}} and '''should be used''' for [[Code Optimisation#Removing elements|performance concerns]].}}
 
=== Going through the array ===
 
The simplest way to iterate through an array is the [[forEach]] command:
 
[[private]] _myArray = [1, 2, 3, 4, 5];
{ [[systemChat]] [[str]] [[_x]] } [[forEach]] _myArray;
 
A combination of [[for]], [[count]] and [[select]] can also be used:
 
[[private]] _myArray = [1, 2, 3, 4, 5];
[[for]] "_i" [[from]] 0 [[to]] '''([[count]] _myArray) -1''' [[do]] { {{codecomment|// [[count]] would return 5, but 5 is at array index 4}}
[[systemChat]] [[str]] (_myArray [[select]] _i);
};
 
 
== Advanced usage ==
 
=== apply ===
 
Similar to the [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map "map" function in Javascript],
[[apply]] allows to apply code to every elements in an array, without changing reference to said array:
 
[[private]] _myArray = [1, 2, 3, 4, 5];
_myArray [[apply]] { [[_x]] [[*]] 2 }; {{codecomment|// _myArray is [2, 4, 6, 8, 10]}}
{{codecomment|// same as}}
[[for]] "_i" [[from]] 0 [[to]] [[count]] _myArray -1 [[do]] {
[[private]] _element = _myArray [[select]] _i;
_myArray [[set]] [_i, _element [[*]] 2];
};
 
=== select ===
 
A simple way to filter an array (and obtain a new one) is using [[select]]'s alternative syntax:


[[private]] _myArray = [1, 2, 3, 4, 5];
{| class="wikitable sortable align-center align-left-col-1"
[[private]] _filteredArray = _myArray [[select]] { [[_x]] > 3 }; {{codecomment|// _filteredArray is [4, 5]}}
|+ Order of Initialisation (use column sorting for respective machine order)
! rowspan="2" class="unsortable" style="text-align: center" | Task
{{codecomment|// same as}}
! rowspan="2" | Exec Environment
[[private]] _filteredArray = [];
! rowspan="1" colspan="5" class="unsortable" | Machine
{ [[if]] ([[_x]] > 3) [[then]] { _filteredArray [[pushBack]] [[_x]] } } forEach _myArray;
|-
! Single Player
! Dedicated Server
! Hosted Server
! Multiplayer Client
! [[Multiplayer Scripting#Join In Progress|JIP]] MP Client


=== findIf ===
|-
| [[Arma 3: Functions Library|Functions]] with <syntaxhighlight lang="cpp" inline>recompile</syntaxhighlight> {{Link|Arma 3: Functions Library#Attributes 3|attribute}} are recompiled
| {{n/a}}
| 1 <!-- Single Player -->
| 1 <!-- Dedicated Server -->
| 1 <!-- Hosted Server -->
| 1 <!-- Multiplayer Client -->
| 1 <!-- JIP MP Client -->


[[findIf]] command allows you to go through the whole list and stop '''as soon as the condition is met''', returning the condition-meeting element's array index:
|-
| [[Arma 3: Functions Library|Functions]] with <syntaxhighlight lang="cpp" inline>preInit</syntaxhighlight> {{Link|Arma 3: Functions Library#Attributes 3|attribute}} are called
| [[Scheduler#Unscheduled Environment|Unscheduled]]
| 2 <!-- Single Player -->
| 2 <!-- Dedicated Server -->
| 2 <!-- Hosted Server -->
| 2 <!-- Multiplayer Client -->
| 2 <!-- JIP MP Client -->


[[private]] _myArray = [1, 2, 3, 4, 5];
|-
{ [[_x]] == 3 } [[findIf]] _myArray == -1; {{codecomment|// returns [[false]], meaning an element equals 3}}
| Object Init Event Handlers are called
{ [[_x]] == 6 } [[findIf]] _myArray == -1; {{codecomment|// returns [[true]],  meaning no elements equal 6}}
| [[Scheduler#Unscheduled Environment|Unscheduled]]
| 3 <!-- Single Player -->
| 3 <!-- Dedicated Server -->
| 3 <!-- Hosted Server -->
| 3 <!-- Multiplayer Client -->
| {{Icon|unchecked}} <!-- JIP MP Client -->


|-
| Expressions of [[Eden Editor: Configuring Attributes|Eden Editor entity attributes]] are called<ref name="isPlayer"><sqf inline>isPlayer _entity</sqf> does not return [[true]] immediately. Once the entity has become a [[player]], it is transferred to the client.</ref>
| [[Scheduler#Unscheduled Environment|Unscheduled]]
| 4 <!-- Single Player -->
| 4 <!-- Dedicated Server -->
| 4 <!-- Hosted Server -->
| {{Icon|unchecked}} <!-- Multiplayer Client -->
| {{Icon|unchecked}} <!-- JIP MP Client -->


Before {{arma3}} you had to use [[count]]:
|-
| Object initialisation fields are called
| [[Scheduler#Unscheduled Environment|Unscheduled]]
| 5 <!-- Single Player -->
| 5 <!-- Dedicated Server -->
| 5 <!-- Hosted Server -->
| 4 <!-- Multiplayer Client -->
| 3 <!-- JIP MP Client -->


[[private]] _myArray = [1, 2, 3, 4, 5];
|- style="background-color: #95F0AD"
{ [[_x]] == 3 } [[count]] _myArray > 0; {{ codecomment|// returns [[true]],  meaning an element equals 3}}
| [[Event Scripts#init.sqs|init.sqs]] is executed
{ [[_x]] == 6 } [[count]] _myArray > 0; {{ codecomment|// returns [[false]], meaning no elements equal 6}}
|
| 6 <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


{{Important | [[findIf]] has been introduced in {{arma3}} and '''should be used''' for [[Code Optimisation#findIf|performance concerns]].}}
|- style="background-color: #95F0AD"
| [[Event Scripts#init.sqf|init.sqf]] is executed
| [[Scheduler#Scheduled Environment|Scheduled]]<ref name="enginewaits">Note '''in single player''' that while the environment is [[Scheduler#Scheduled Environment|Scheduled]] ([[canSuspend]] returns true), the engine seems to wait until the script is done executing, essentially behaving similarly to an [[Scheduler#Unscheduled Environment|Unscheduled environment]] - infinite loops will freeze the game, [[uiSleep]] may pause the game for up to ~20s (postInit), [[waitUntil]] can cause catastrophic issues, etc.</ref>
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


=== arrayIntersect ===
|-
| Expressions of [[Eden Editor: Configuring Attributes|Eden Editor scenario attributes]] are called<ref name="playerCommandNotAvailable">[[player]] is not available immediately.</ref>
| [[Scheduler#Unscheduled Environment|Unscheduled]]
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


The [[arrayIntersect]] command returns a new array filled with the items found in both provided lists:
|- style="background-color: #95DEF0"
| Persistent functions are called
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


[[private]] _array1 = [1, 2, 3, 4];
|-
[[private]] _array2 = [3, 4, 5, 6];
| [[Modules]] are initialised
[[private]] _result = _array1 [[arrayIntersect]] _array2; {{codecomment|// _result is [3, 4]}}
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| {{Icon|unchecked}} <!-- JIP MP Client -->


=== Sorting an array ===
|- style="background-color: #DEF0AD"
| [[Event Scripts#initServer.sqf|initServer.sqf]] is executed
| [[Scheduler#Scheduled Environment|Scheduled]]
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| {{n/a}} <!-- Multiplayer Client -->
| {{n/a}} <!-- JIP MP Client -->


==== sort ====
|- style="background-color: #DEF0AD"
| [[Event Scripts#initPlayerLocal.sqf|initPlayerLocal.sqf]] is executed
| [[Scheduler#Scheduled Environment|Scheduled]]
| <!-- Single Player -->
| {{n/a}} <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


The [[sort]] command allows for sorting an array of [[String]], [[Number]] or sub-[[Array]]s of string/number. It modifies the original array and '''does not return anything''':
|- style="background-color: #DEF0AD"
| [[Event Scripts#initPlayerServer.sqf|initPlayerServer.sqf]] is executed on the server
| [[Scheduler#Scheduled Environment|Scheduled]]
| <!-- Single Player -->
| {{n/a}} <!-- Dedicated Server -->
| ?? <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


[[private]] _myArray = ["zzz", "aaa", "ccc"];
|-
_myArray [[sort]] [[true]]; {{codecomment|// _myArray is ["aaa", "ccc", "zzz"]}}
| [[Arma 3: Functions Library|Functions]] with <syntaxhighlight lang="cpp" inline>postInit</syntaxhighlight> {{Link|Arma 3: Functions Library#Attributes 3|attribute}} are called
| [[Scheduler#Scheduled Environment|Scheduled]]<ref name="enginewaits"/>
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


[[private]] _myArray = [666, 57, 1024, 42];
|- style="background-color: #95DEF0"
_myArray [[sort]] [[false]]; {{codecomment|// _myArray is [1024, 666, 57, 42]}}
| [[Event Scripts#init.sqs|init.sqs]] is executed
| [[Scheduler#Scheduled Environment|Scheduled]]
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


[[private]] _myArray = <nowiki>[["zzz", 0], ["aaa", 42], ["ccc", 33]];</nowiki>
|- style="background-color: #95DEF0"
_myArray [[sort]] [[true]]; {{codecomment|// _myArray is <nowiki>[["aaa", 42], ["ccc", 33], ["zzz", 0]]</nowiki>}}
| [[Event Scripts#init.sqf|init.sqf]] is executed
| [[Scheduler#Scheduled Environment|Scheduled]]
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


==== reverse ====
|-
| [[remoteExec]]'s [[Multiplayer Scripting#Join In Progress|JIP]] queue
| {{n/a}}
| {{n/a}} <!-- Single Player -->
| {{n/a}} <!-- Dedicated Server -->
| {{n/a}} <!-- Hosted Server -->
| {{n/a}} <!-- Multiplayer Client -->
| 42 <!-- JIP MP Client -->


The [[reverse]] command simply reverses the array order:
|- style="background-color: #EEE"
[[private]] _myArray = [99, 33, 17, 24, "a", [3,2,1], 7777];
| ''Scenario going''
[[reverse]] _myArray; {{codecomment|// _myArray is [7777, [3,2,1], "a", 24, 17, 33, 99]}}
| {{n/a}}
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


==== BIS_fnc_sortBy ====
|-
| [[Event Scripts#exit.sqf|exit.sqf]]
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


The function [[BIS_fnc_sortBy]] has been created for more complex sorting. Its algorithm input must return a number:
|-
| [[Event Scripts#exit.sqs|exit.sqs]]
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


[[private]] _closestHelicopters = <nowiki>[</nowiki>[_heli1, _heli2, _heli3], [], { [[player]] [[distance]] [[_x]] }, "ASCEND"] [[call]] [[BIS_fnc_sortBy]];
|-
| {{Link|Arma 3: Mission Event Handlers#Ended|"Ended" Mission Event Handler}}
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


|-
|  {{Link|Arma 3: Mission Event Handlers#MPEnded|"MPEnded" Mission Event Handler}}
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


== Common errors ==
|}


=== Index rounding ===
In Arma scripts, indices are rounded to the nearest whole number.
A boundary case (X.5, where X is any whole number) rounds to the nearest '''even''' whole number.


;Boundary cases:
== See Also ==
* -0.5 <= index <= 0.5 rounds to 0
* &nbsp;0.5 <&nbsp; index <&nbsp; 1.5 rounds to 1
* &nbsp;1.5 <= index <= 2.5 rounds to 2
* &nbsp;2.5 <&nbsp; index <&nbsp; 3.5 rounds to 3


;In short:
* [[Arma 3: Functions Library]]<!--
* -0.5 rounds '''up''' to 0
* [[Arma 2: Functions Library]] -->
* &nbsp;0.5 rounds '''down''' to 0
* [[Arma 3: Remote Execution]], [[BIS_fnc_MP]] <!-- keep? -->
* &nbsp;1.5 rounds '''up''' to 2
* [[Eden Editor: Configuring Attributes|Eden Editor: Configuring Attributes]]
* &nbsp;2.5 rounds '''down''' to 2
* [[Event Scripts]]
* &nbsp;3.5 rounds '''up''' to 4
* [[Scheduler]]
etc.
 
<!--
=== Index out of Range ===
 
If a rounded index refers to a position in an array that is invalid:
* If the index is negative, an [[Error Zero Divisor]] error message will be displayed.
* If the index is positive, the returned value will be of the [[Nothing|null type]].
 
_array = [];
_element = (_array select 0)
 
_array = ["element"];
_element = (_array select 1)
 
_array = ["element"];
_element = (_array select -1)
''Accesses which are in bounds'':
_array = ["element"];
_element = (_array select 0)
 
_array = ["element"];
_element = (_array select 0.1)
 
_array = ["element"];
_element = (_array select -0.3)
-->
If the index given to the [[set]] command is out of bounds:
* If the index rounded to a negative number, then an [[Error Zero Divisor]] message will be displayed in game.
* If the index rounded to a positive number, then the array will [[resize]] to incorporate the index ''as its last value''. Each element between the last valid element, and the new [[set]] element, will be the [[Nothing|null type]]
 
=== Bad syntax ===
 
{{codecomment|// Error: Unexpected ","}}
[[private]] _myErroneousArray = ["Weapon1", "Weapon2", "Weapon3",]; {{codecomment|// The last element in an array must exclude the ","}}
 
 
[[:Category: Data Types]]
 
[[Category: Sandbox]]

Latest revision as of 01:29, 18 March 2024

Order of Initialisation (use column sorting for respective machine order)
Task Exec Environment Machine
Single Player Dedicated Server Hosted Server Multiplayer Client JIP MP Client
Functions with recompile attribute are recompiled N/A 1 1 1 1 1
Functions with preInit attribute are called Unscheduled 2 2 2 2 2
Object Init Event Handlers are called Unscheduled 3 3 3 3 Unchecked
Expressions of Eden Editor entity attributes are called[1] Unscheduled 4 4 4 Unchecked Unchecked
Object initialisation fields are called Unscheduled 5 5 5 4 3
init.sqs is executed 6
init.sqf is executed Scheduled[2]
Expressions of Eden Editor scenario attributes are called[3] Unscheduled
Persistent functions are called
Modules are initialised Unchecked
initServer.sqf is executed Scheduled N/A N/A
initPlayerLocal.sqf is executed Scheduled N/A
initPlayerServer.sqf is executed on the server Scheduled N/A ??
Functions with postInit attribute are called Scheduled[2]
init.sqs is executed Scheduled
init.sqf is executed Scheduled
remoteExec's JIP queue N/A N/A N/A N/A N/A 42
Scenario going N/A
exit.sqf
exit.sqs
"Ended" Mission Event Handler
"MPEnded" Mission Event Handler


See Also

  1. isPlayer _entity does not return true immediately. Once the entity has become a player, it is transferred to the client.
  2. 2.0 2.1 Note in single player that while the environment is Scheduled (canSuspend returns true), the engine seems to wait until the script is done executing, essentially behaving similarly to an Unscheduled environment - infinite loops will freeze the game, uiSleep may pause the game for up to ~20s (postInit), waitUntil can cause catastrophic issues, etc.
  3. player is not available immediately.