Jump to content
austin_medic

Trying to pass data into a script, first element becomes null before it gets into the script

Recommended Posts

so im trying to pass data into a script, but the first element becomes null before it gets into the script, at least from what I can tell with debugging.

 

I've tried using private, passing the variable in through different formats (e.g using the array position itself instead of a variable, and using a variable, nither worked). 

 

heres the debug lines,

 

11:49:44 "TILE SYSTEM :: [10553,21541.1,0]" //the position of the tile
11:49:44 "TILE SYSTEM :: [OPS]" //units found inside that tile
11:49:44 "TILE SYSTEM :: [[10553,21541.1,0],2000,"",900] //params i want to pass to the script from my tile system loop
11:49:44 "FIND LOC :: any - 2000 - "" - 900" // params passed into my find location script 

no matter what I do the position passed in always becomes any before the script even begins.

 

Any ways to fix this?

 

 

heres my tile system loop

	[] spawn
	{
		while{true} do
		{
			{
				_variableName = format["visit_%1",_x];
				_townVisits = profileNamespace getVariable [_variableName,0];
				_variableName = format["coolDown_%1",_x];
				_onCoolDown = profileNamespace getVariable [_variableName,0];
				diag_log format["TILE SYSTEM :: %1 - %2",_townVisits,_onCoolDown];
				_enemyCount = 2 + round(random 2);
				if(_townVisits > 3) then
				{
					_enemyCount = 2 + round(random 1);
				};
				if(_townVisits > 5) then
				{
					_enemyCount = 1 + round(random 1);
				};
				if(_townVisits > 9) then
				{
					_enemyCount = 0;
				};
				private "_markerPosition";
				_markerPosition = getMarkerPos _x;
				diag_log format["TILE SYSTEM :: %1",_markerPosition];
				_nearbyUnits = [_markerPosition,1000] call AUSMD_fnc_nearUnits;
				diag_log format["TILE SYSTEM :: %1",_nearbyUnits];
				if(count _nearbyUnits > 0 && _onCoolDown isEqualTo 0) then
				{
					_loc = [[10553,21541.1,0],2000,"",900] call AUSMD_fnc_findLoc; /////problem occurs here
					diag_log format["TILE SYSTEM :: %1",_loc];
					
					_group = [enemySide,50,_loc] call AUSMD_fnc_createGroup;
					_chaseUnit = [getPos leader _group] call AUSMD_fnc_nearUnits;
					[_group,_chaseUnit] call BIS_fnc_taskAttack;
					_variableName = format["coolDown_%1",_x];
					profileNamespace setVariable [_variableName,200];
					saveProfileNamespace;
				};
				if(!(_onCoolDown isEqualTo 0)) then
				{
					_variableName = format["coolDown_%1",_x];
					_coolDownTime = profileNamespace getVariable [_variableName,0];
					diag_log format["TILE SYSTEM :: %1",_coolDownTime];
					profileNamespace setVariable [_variableName,(_coolDownTime - 1)];
					saveProfileNamespace;
				};
			} forEach AUSMD_gridPositions;
			sleep 30;
		};
	};

my find location function


_centerPos = _this select 0;
_maxDist = _this select 1;
_object = _this select 2;
_minDist = _this select 3;
_blacklistLoc = _this select 4;

scopeName "main";

if(typeName _centerPos isEqualTo "OBJECT") then
{
	_centerPosN = getPos _centerPos;
}
else
{
	_centerPosN = _centerPos;
};

diag_log format ["FIND LOC :: %1 - %2",_centerPosN,_maxDist];

if(count _this < 3) then
{
	_object = "";
};

if(count _this < 4) then
{
	_minDist = 5;
};
if(count _this < 5) then
{
	_blacklistLoc = [0,0,0];
};

_loop = 0;

_posNow = [];

_isFlat = [];

for "_i" from 0 to 800 do
{
	scopeName "loop";
	_loop = _loop + 1;
	_posNow = [(_centerPosN select 0) + (random _maxDist - random _maxDist),(_centerPosN select 1) + (random _maxDist - random _maxDist),0];
		
	if(_object isEqualTo "") then
	{
		_isFlat = _posNow isFlatEmpty 
		[
			5,	//--- Minimal distance from another object
			0,				//--- If 0, just check position. If >0, select new one
			0.7,				//--- Max gradient
			8,	//--- Gradient area
			0,				//--- 0 for restricted water, 2 for required water,
			false,				//--- True if some water can be in 25m radius
			objNull
		];
	}
	else
	{
		_isFlat = _posNow isFlatEmpty 
		[
			(sizeof _object) / 2,	//--- Minimal distance from another object
			0,				//--- If 0, just check position. If >0, select new one
			0.7,				//--- Max gradient
			(sizeof _object),	//--- Gradient area
			0,				//--- 0 for restricted water, 2 for required water,
			false,				//--- True if some water can be in 25m radius
			objNull
		];
	};

	if(_loop > 50) then
	{
		_loop = 0;
		_centerPosN set[0,(_centerPosN select 0) + (random 800 - random 800)];
		_centerPosN set[1,(_centerPosN select 1) + (random 800 - random 800)];
		diag_log "FIND LOC :: Changing base location because no match was found...";
	};
	
	_nearPlayers = [];
	{
		if(_x distance _posNow < 1000) then
		{
			_nearPlayers set[count _nearPlayers,_x];
		};
	} forEach allPlayers;
	
	_nearFriendlyTile = [_posNow,1000] call AUSMD_fnc_findNearestTileF;
	
	if(!(_isFlat isEqualTo []) && !(_nearFriendlyTile isEqualTo "") && _posNow distance _blacklistPos > _minDist && count _nearPlayers isEqualTo 0 && _posNow distance (getMarkerPos "HQ") > 700 && _posNow distance (getMarkerPos "Respawn_West") > 500 && _posNow distance (getMarkerPos "PB1") > 700 && _posNow distance (getMarkerPos "PB2") > 700 && _posNow distance (getMarkerPos "PB3") > 700) then {breakTo "main";};
	
	diag_log format ["FIND LOC :: Searching for location again...  old location : %1",_posNow];
};
diag_log format ["FIND LOC :: Exiting, location found : %1",_isFlat];

_isFlat;

Share this post


Link to post
Share on other sites

The local variable _centerPosN is hidden inside of the IF scope so is not available outside of it.

Private the variable _centerPosN at the top of your script or at minimum at least define it before the if statement. Or just use _centerPos inside the if much like you have for _object , _minDist and _blacklistLoc rather than making a new variable.

params[
	[ "_centerPos", [], [ objNull, [] ] ],
	[ "_maxDist", 2000, [ 0 ] ],
	[ "_object", "", [ objNull, "" ] ],
	[ "_minDist", 5, [ 0 ] ],
	[ "_blacklistLoc", [0,0,0], [ [] ] ]
];

scopeName "main";

if(typeName _centerPos isEqualTo "OBJECT") then
{
	_centerPos = getPos _centerPos;
};

_loop = 0;

//SNIP - rename any following _centerPosN to _centerPos

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

×