Jump to content
Sign in to follow this  
alleycat

forEach problem

Recommended Posts

hintsilent "test2";
////////FOR EACH HOUSE////////////////////////////////////////////////
{
//Counts the amount of positions (=loot spots)
_c = 0;
while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
_spawnlocs = _c;

//as long as there are spawn locations not processed:
while {_spawnlocs > 0} do {


	//roll dice for each lootspot (starts with topmost)
	if ((random 1) < 1) then {
		_loot  = createVehicle ["TKBasicAmmunitionBox_EP1", (_x buildingpos _spawnlocs), [], 0, "can_collide"];    
			_posx = (_x buildingpos _spawnlocs) select 0;
			_posy = (_x buildingpos _spawnlocs) select 1;
			_posz = (_x buildingpos _spawnlocs) select 2;

		clearweaponcargoglobal _loot;
		clearmagazinecargoglobal _loot;
		_loot setpos [_posx,_posy,(_posz)];
		_loot addWeaponCargoGlobal ["MetisLauncher",1];
		_total_loot = _total_loot +1;
	};

     _spawnlocs = _spawnlocs - 1;
};
hintsilent "test3";
} forEach _loot_house_list;


hintsilent "test4";

What is wrong with this? It never gets to "test4". The last hintsilent displayed is "test3"

---------- Post added at 11:59 AM ---------- Previous post was at 11:30 AM ----------

hintsilent "test2";
////////FOR EACH HOUSE////////////////////////////////////////////////
{
   //Counts the amount of positions (=loot spots)
   _c = 0;
   while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
   _spawnlocs = _c;

   //as long as there are spawn locations not processed:
   while {_spawnlocs > 0} do {


       //roll dice for each lootspot (starts with topmost)
       if ((random 1) < 1) then {
           _loot  = createVehicle ["TKBasicAmmunitionBox_EP1", (_x buildingpos _spawnlocs), [], 0, "can_collide"];    
               _posx = (_x buildingpos _spawnlocs) select 0;
               _posy = (_x buildingpos _spawnlocs) select 1;
               _posz = (_x buildingpos _spawnlocs) select 2;

           clearweaponcargoglobal _loot;
           clearmagazinecargoglobal _loot;
           _loot setpos [_posx,_posy,(_posz)];
           _loot addWeaponCargoGlobal ["MetisLauncher",1];
           _total_loot = _total_loot +1;
       };

        _spawnlocs = _spawnlocs - 1;
   };
   hintsilent "test3";
} forEach _loot_house_list;


hintsilent "test4";

Found the problem, it is the "if random" code. But I am not sure how to fix it. I would like to apply foreach to each _spawnlocs. How do I nest 2 forEach? is that even possible?

---------- Post added at 12:31 PM ---------- Previous post was at 11:59 AM ----------

Actually, skip that, avoided the nesting by packing the spawning into a script.

Edited by alleycat

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  

×