Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
SRBuckey5266

Local variable not within scope of while loop

Recommended Posts

Why is it that anything below the OnMapSingeClick function, nothing can "see" the _runallaharkkabar variable? E.G: My while loop won't run, and the hint "true" is never displayed.

_runallahakkbar = true;
_start = false;
_unitstk = [];

numTanks = 0;
numAA = 0;
numTroopCarriers = 0;

onMapSingleClick{
if(_shift) then {

	//positioning
	_ylength = -2350;
	_xlength = 0;
	_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 ["55_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;

		//add vehicle to units array
		if(count _unitstk == 0) then {
			_unitstk set [0, _tank];
		}else{
			_unitstk set [(count _unitstk + 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;

		//add vehicle to units array
		if(count _unitstk == 0) then {
			_unitstk set [0, _aa];
		}else{
			_unitstk set [(count _unitstk + 1), _aa];
		};

		_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;

		//add vehicle to units array
		if(count _unitstk == 0) then {
			_unitstk set [0, _truck];
		}else{
			_unitstk set [(count _unitstk + 1), _truck];
		};

		_c = _c + 1;
	};

	//make the squad leader the leader of group
	_group selectLeader (unitstk select 0);

	//delete marker if already set
	if(getMarkerColor "Squad_spawn" == "") then {
		deleteMarker "Squad_Spawn";
	};

	_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;
};

if(_runallahakkbar) then {
hint "true";
};

while { _runallahakkbar } do {
hint "";
if(_start) then {
	{
		if(!alive _x) then {
			hint format["%1 is down. (%2/%3) units left.", _x, (count _unitstk), ((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 _unitstk;

			_unitstk = _build;
		};
	} foreach _unitstk;

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

sleep 3;
};

Share this post


Link to post
Share on other sites

dont have the time right now but try making the local variable a global variable like this

a local looks like this _runallahakkbar

a glkobal looks like this runallahakkbar

not no underscore

that way it can be read from anywhere.

you most likely knew that but i dont know what you know so just trying to help

unless your using _runallahakkbar somewhere else for different reasons then making it a global will not effect anything

---------- Post added at 09:44 ---------- Previous post was at 09:40 ----------

out of curiosity are you using show error hints then checking your error rpt log

FOUND HERE

C:\Documents and Settings\"YOUR USERNAME"\Application Data\ArmA 2 OA;

http://forums.bistudio.com/showthread.php?137306-How-to-check-my-RPT-log

Share this post


Link to post
Share on other sites
Sign in to follow this  

×