Home   Help Search Login Register  

Author Topic: ForEach inside ForEach  (Read 2634 times)

0 Members and 1 Guest are viewing this topic.

Offline SaOk

  • Missions Depot Staff
  • *****
    • My youtube profile
ForEach inside ForEach
« on: 02 Mar 2011, 13:26:02 »
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;
« Last Edit: 02 Mar 2011, 15:08:37 by SaOk »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: ForEach inside ForEach
« Reply #1 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;
urp!

Offline SaOk

  • Missions Depot Staff
  • *****
    • My youtube profile
Re: ForEach inside ForEach
« Reply #2 on: 02 Mar 2011, 16:58:07 »
Thanks, I will try that next time. :)