Jump to content
Sign in to follow this  
SRBuckey5266

Anything wrong with this block of code?

Recommended Posts

	{
		if(!alive _x) then {
			//hint format["%1 is down. (%2/%3) units left.", _x, ((count units), (count numAA)+(count numTroopCarriers)+(numTanks))];

			//remove from units array
			_build = [];
			_i = _x;

			{
				if(_x != _i) then {
					if(count _build == 0) then {
						_build set [0, _x];
					}else{
						_build set [(count _build + 1), _x];
					};
				};
			} foreach units;

			units = _build;
		};
	} foreach units;

I removed this bit of code from my script, and then it magically started working again. I've been trying to hunt down the bug....

When that code block is left in, my while loop does not run at all.

FULL CODE:

runallahakkbar = false;
sleep 5;

runallahakkbar = true;
start = false;
units = [];

numTanks = 3; //NEED AT LEAST 1 TANK
numAA = 0; //include in tanks array
numTroopCarriers = 0;

onMapSingleClick{
if(_shift) then {

	//positioning
	_ylength = -1000;
	_xlength = 5000;
	_upos = nil;
	_sl = nil;

	//group for them all to go in
	_group = createGroup east;

	_c = 0;
	for "_x" from 1 to numTanks do {
		_tank = createVehicle ["T55_TK_EP1", [(_pos select 0)+(_c * 4)+(_xlength),(_pos select 1)+(_ylength),(_pos select 2)], [], 0, "FORM"];

		_driver = _group createUnit ["TK_Soldier_Crew_EP1", _pos, [], 0, "FORM"]; _driver moveInDriver _tank;
		_gunner = _group createUnit ["TK_Soldier_Crew_EP1", _pos, [], 0, "FORM"]; _gunner moveInGunner _tank;
		_commander = _group createUnit ["TK_Soldier_Crew_EP1", _pos, [], 0, "FORM"]; _commander moveInCommander _tank;

		_driver doMove _pos;
		_upos = getPos _tank;

		if(count units == 0) then {
			units set [0, _tank];
		}else{
			units set [(count units + 1), _tank];
		};

		//the last commander created
		if(_x == numTanks) then { _sl = _commander; };

		_c = _c + 1;
	};

	_c = 0;
	for "_x" from 1 to numAA do {
		_aa = createVehicle ["ZSU_TK_EP1", [(_pos select 0)+(_c * 4)+(_xlength),(_pos select 1)+(_ylength)-32,(_pos select 2)], [], 0, "FORM"];

		_driver = _group createUnit ["TK_Soldier_Crew_EP1", _pos, [], 0, "FORM"]; _driver moveInDriver _aa;
		_gunner = _group createUnit ["TK_Soldier_Crew_EP1", _pos, [], 0, "FORM"]; _gunner moveInGunner _aa;

		_driver doMove _pos;

		_c = _c + 1;
	};


	_c = 0;
	for "_x" from 1 to numTroopCarriers do {
		_truck = createVehicle ["KamazOpen", [(_pos select 0)+(_c * 4)+(_xlength),(_pos select 1)+(_ylength)-24,(_pos select 2)], [], 0, "FORM"];

		_driver = _group createUnit ["TK_Soldier_AT_EP1", _pos, [], 0, "FORM"]; _driver moveInDriver _truck;

		//fill truck with troops
		for "_x" from 1 to 12 do {
			_soldier = "";
			switch (true) do {
				case (_x <= 6): 
				{
					_soldier = "TK_Special_Forces_EP1";
				};
				case (_x > 6 && _x <= 10): 
				{
					_soldier = "TK_Soldier_AT_EP1";
				};
				case (_x > 10):
				{
					_soldier = "TK_Soldier_SniperH_EP1";
				};
			};

			_troop = _group createUnit [_soldier, [(_pos select 0)+(_c * 4)+(_xlength),(_pos select 1)+(_ylength)-32,(_pos select 2)], [], 0, "FORM"]; 
			_troop moveInCargo _truck;
		};


		_driver doMove _pos;

		_c = _c + 1;
	};

	//make the squad leader the leader of group
	_group selectLeader _sl;

	_marker = createMarker ["Squad_marker", _upos ];
	"Squad_marker" setMarkerType "o_armor";
	"Squad_marker" setMarkerSize [1, 1];
	"Squad_marker" setMarkerDir 0.93884;
	"Squad_marker" setMarkerText "Armored Division";
	"Squad_marker" setMarkerColor "ColorRed";
	"Squad_marker" setMarkerPos _upos;
};

start = true;
};

while { runallahakkbar } do {
if(start) then {
	{
		if(!alive _x) then {
			//hint format["%1 is down. (%2/%3) units left.", _x, ((count units), (count numAA)+(count numTroopCarriers)+(numTanks))];

			//remove from units array
			_build = [];
			_i = _x;

			{
				if(_x != _i) then {
					if(count _build == 0) then {
						_build set [0, _x];
					}else{
						_build set [(count _build + 1), _x];
					};
				};
			} foreach units;

			units = _build;
		};
	} foreach units;

	if(count units > 0) then {
		//set new tank marker, in case original tank moving it was destroyed
		"Squad_marker" setMarkerPos (getPos (units select 0));
	}else{
		hint "Units are dead";
		deleteMarker "Squad_marker";
		runallahakkbar = false;
	};
};

sleep 3;
};

Share this post


Link to post
Share on other sites

yeah for a starters from a quick look

units

Arma already uses units so you cant use that as your global variable name. thats going to cause conflicts

also i could have missed it but i cant see anywhere after you spawn your units where you add them to the units array

it should look like this to add them


_driver = _group createUnit ["TK_Soldier_AT_EP1", _pos, [], 0, "FORM"]; _driver moveInDriver _truck;

units set[(count units ), _driver ];

bit late here and eyes are hanging out my head ill look a bit better tomoz

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  

×