Jump to content
Sign in to follow this  
unknownx9

Problem with arrays

Recommended Posts

Hello,

I am trying to do the following :

  1. Create an Array
  2. Assign the individual elements of the Array values
  3. After I am done using the array elements set them back to empty

private["_location1","_location2","_location3","_location4","_groups","_route","_selectedLocation","_groupVariable"];

_route = _this select 0;

//Route 1
_location1 = [[513.62207,2746.9282,310.05081],[330.89847,2698.4902,291.2688],[261.56473,2774.7625,285.56805],[151.06387,2687.646,304.80322]];

//Route 2
_location2 = [[322.29877,3026.4014,285.99854],[259.63757,3213.3926,275.20633],[379.46701,3360.7385,275.84738],[194.46994,3453.6235,244.57669]];

//Route 3
_location3 = _location2 + [383.2887,3590.7268,246.25278];

//Route 3
_location4 = _location3 + [[642.60834,3516.9346,283.97449],[779.95288,3585.0515,278.79163],[1022.7352,3554.5818,298.41965],[1332.6926,3689.5344,251.16754],[1604.546,3643.4819,238.99081]];

//Add groups to groups array
_groups = ["_group1","_group2","_group3","_group4"];

//Create an HQ for east
_eastHQ = createCenter east;

switch(_route) do
{
case 1:
{
	for [{_i=0},{_i<=2},{_i=_i+1}] do
	{
		_selectedLocation = _location1 call BIS_fnc_selectRandom;
		(_groups select _i) = createGroup east;
		(_groups select _i) = [_selectedLocation, EAST, 5] call BIS_fnc_spawnGroup;
		[(_groups select _i), _selectedLocation, 10] call bis_fnc_taskPatrol;
		hint format ["Location: %1 Selected Group: %2",_selectedLocation,(_groups select _i)];
		sleep 5;
	};
};
etc...

Problems arise in the for loop which is where I am trying to assign values to the array elements. Basically I am trying to make that array a variable holder, which contains groups.

Would really appreciate the help,

Thanks.

Share this post


Link to post
Share on other sites

I'm not really sure about what you're trying to do. Here is what I would go with:

private["_locations","_groups","_route","_selectedLocation"];
waituntil {!isnil "bis_fnc_init"};

_route = (_this select 0) - 1;

_locations = [
[[513.62207,2746.9282,310.05081],[330.89847,2698.4902,291.2688],[261.56473,2774.7625,285.56805],[151.06387,2687.646,304.80322]],
[[322.29877,3026.4014,285.99854],[259.63757,3213.3926,275.20633],[379.46701,3360.7385,275.84738],[194.46994,3453.6235,244.57669]],
[[383.2887,3590.7268,246.25278]],
[[642.60834,3516.9346,283.97449],[779.95288,3585.0515,278.79163],[1022.7352,3554.5818,298.41965],[1332.6926,3689.5344,251.16754],[1604.546,3643.4819,238.99081]]
];

_groups = [];

_eastHQ = createCenter east;

for "_i" from 0 to 2 do {
_selectedLocation = _locations select _route call BIS_fnc_selectRandom;
_tempGroup = [_selectedLocation, EAST, 5] call BIS_fnc_spawnGroup;
[_tempGroup, _selectedLocation, 10] call bis_fnc_taskPatrol;
_groups set [_i, _tempGroup];
hint format ["Location: %1 Selected Group: %2",_selectedLocation, _tempGroup];
sleep 5;
};
sleep 2;
hint format ["groups array: %1", _groups];

That last hint shows you the array containing groups, which I believe is what you needed?

Share this post


Link to post
Share on other sites

Hello BlackMamb,

First thank you for your reply, it helped me in what I was trying to accomplish.

I have a question about that _tempGroup variable, if I wanted to rename it with each increment of _i and add the _i value to the end of it, how would I do that?

(_tempGroup + _i + "") would work?

Thanks again for your help.

Share this post


Link to post
Share on other sites

Format it, such as

call compile format ['_tempGroup%1 = blabla;', _i];

Share this post


Link to post
Share on other sites
Format it, such as

call compile format ['_tempGroup%1 = blabla;', _i];

Thanks.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×