Forum Jump :

Author Message


Posts: 1
Rank:


Level: Member

Country: 00
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2017-10-15 21:26        
     
in my init.sqf, I have an array, "A_positions", which is constructed like so:

collect_markers = {
	_letter = _this select 0;
	_array = [];
	_n = 1;
	while { true } do {
		scopeName "loop1";
		_marker_name = format["%1%2", _letter, _n];
		_n = _n + 1;
		if (getMarkerColor _marker_name == "") 
		then {
			breakOut "loop1";
		} else { 
			_array = _array + [_marker_name]; 
		}
	};
	
	_array
	
};
A_positions = ["A"] call collect_markers;
missionNamespace setVariable ["A_positions", A_positions];

A unit in my mission might have in his init field this code:

nul = [this,"A_positions"] execVM "random_start_position.sqf";

the script "random_start_position.sqf" takes the argument "A_positions", uses it to reference the array "A_positions", selects a random element from that array, and then deletes that element from the array, so that it wont be used again.

_self = _this select 0;
_positions = _this select 1;
_positions = missionNamespace getVariable _positions;
_count = count _positions;
if (_count > 0) then {
	_r = floor (random _count);	
	_marker = _positions select _r;
	_positions = _positions - [_marker];  //deleting marker from array here
	_pos = getMarkerPos _marker;
	_dir = markerDir _marker;
	_self setPosATL _pos;
	_self setDir _dir; 
	_self forcespeed 0; 
	dostop _self; 
	_self disableAI "TARGET";
	_marker_text = markerText _marker;
	switch (_marker_text) do {
		case "UP": { _self setUnitPos "UP"; };
		case "MIDDLE": { _self setUnitPos "MIDDLE"; };
		case "DOWN": { _self setUnitPos "DOWN"; };
	};
};

The problem is this. While the element "_marker" is indeed deleted from the array contained in the variable "_positions", no change is made to the array "A_positions", which "_positions" is supposed to point to. It appears that a copy of "A_positions" is being assigned to "_positions", but what I really need is for "_positions" to be a reference to "A_positions", so that any change to "_positions" affects "A_positions".