Page MenuHomeFeedback Tracker

getVariable returns a pointer
New, WishlistPublic


If you store an array return value when using getVariable, it will create a pointer and not a new array. If you use set command for the return value, it will do the same for the variable in the variable space.

I created a repro mission and the hint messages will guide you through it, step by step. {F22508}


Legacy ID
Steps To Reproduce
  1. open the repro mission
  2. preview
  3. read the hint boxes
  4. setVariable is used to store an array
  5. this is stored to a variable with getVariable
  6. set command is used to change the first element
  7. substraction is used to remove the first element
  8. getVariable is used again, it's different from the first one

Note that the 2nd getVariable returns [-1, "2nd"], so the substraction didn't do anything to the variable in variable space of the logic.

Additional Information

It is possible to bypass this bug by using _variable = +_returnValue;
But it would be better if this is going to get fixed. This is a bug in Arma 2 as well.

Event Timeline

Gekkibi edited Steps To Reproduce. (Show Details)Oct 11 2013, 10:58 PM
Gekkibi edited Additional Information. (Show Details)
Gekkibi set Category to Scripting.
Gekkibi set Reproducibility to Always.
Gekkibi set Severity to None.
Gekkibi set Resolution to Open.
Gekkibi set Legacy ID to 2534981135.May 7 2016, 5:07 PM

If I recall correctly, this is all intended behavior of arrays. Arrays being passed by reference is one of their most valuable characteristics, and trying to change that would break a LOT of existing scripts, to no noteworthy benefit.

The biggest quirk that is probably throwing causing problems for you is how ARMA handles array addition and subtraction. When you do _array1 = _array1 - _array2;, you are actually creating a completely new array in the process, that just happens to contain the contents of _array1 minus the contents of _array2, then assigning _array1 to reference the new array. That's why the variable within the object didn't get changed by the subtraction, but did by the set. Set, select, and resize are the 3 commands that I can think of that for directly manipulating arrays, while addition and subtraction return copies.

And as you mentioned, using _newArray = +_oldArray; creates a copy of _oldArray and stores it's reference in _newArray, and gives you all the functionality you are asking for.

Edit: Relevant wiki article:

Gekkibi added a subscriber: Gekkibi.May 7 2016, 5:07 PM

Yes, adding or substracting will create a new copy of an array. I used it to demonstrate that getVariable creates an actual pointer. But would it be logical if...

_var = getPos player;
_var set [2, 1000];

...would suddenly teleport you midair..? :P