OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: SaOk on 02 Mar 2011, 13:26:02

Title: ForEach inside ForEach
Post by: SaOk on 02 Mar 2011, 13:26:02
How can I get this kind of code to work with multiple ForEach-commands? The problem is 2 _x´s in (_x distance _x)

Code: [Select]
{if (({_x distance _x > 300;} count (units group player)) > 0) then {deletevehicle _x;_tableAnimal = _tableAnimal - [_x]; _countAnimal = _countAnimal - 1;};} foreach _tableAnimal;
It says something about _forEachIndex in here, but I dont understand it yet: http://community.bistudio.com/wiki/forEach

I would need a single line to check distances between objects in two dynamic size arrays.

Edit: I scripted it in another way, but if foreach inside foreach is possible, let me know:

Code: [Select]
_closestU = (units group player) select 0;
_disU  = _closestU distance _center;
{if(_x distance _center < _disU) then {_disU = _closestU distance _center; _closestU= _x;};} foreach (units group player);

{if (_closestU distance _x > 300) then {deletevehicle _x;_tableAnimal = _tableAnimal - [_x]; _countAnimal = _countAnimal - 1;};} foreach _tableAnimal;
Title: Re: ForEach inside ForEach
Post by: Mr.Peanut on 02 Mar 2011, 16:50:14
Code: [Select]
{ _y = _x; if (({_y distance _x > 300;} count (units group player)) > 0) then {deletevehicle _x;_tableAnimal = _tableAnimal - [_x]; _countAnimal = _countAnimal - 1;};} foreach _tableAnimal;
Title: Re: ForEach inside ForEach
Post by: SaOk on 02 Mar 2011, 16:58:07
Thanks, I will try that next time. :)