Jump to content
Sign in to follow this  
R0T

Skript Error Question

Recommended Posts

Hey Folks,

i wrote a skript for a random patrol but now stuck on a expression that the game throws at me and i can't find my mistake :confused:

the error

if (((getPos leader _Pat)distance _posNew)< 35) then 
{
if (_wait) then 
{>
 Error position: <_posNew)< 35) then 
{
if (_wait) then 
{>
 Error Undefined variable in expression: _posnew
File C:\Users\Sam.N.Raub\Documents\Arma 3\missions\JSP_JustSimplePatrol.Altis\JSP.sqf, line 212
Error in expression <;
};

My problem is this error occurs just for the first run after i started arma 3 and run the skript the first time. The second time i run the skript the error is gone.For me it looks like i don't have defined the variable _posNew (is a array that have a position in it [x,y,z]) not right but i did it at the beginning of the skript. I hope someone can help. Im really at the beginning with scripting. When anybody see something that could be improved ... pleas gimmi a hint so i can learn somthing new.

Her is the whole skript

/*--------------------------------------------------------------------------*/
/*------------------------------- - JSP.sqf - ------------------------------*/
/*--------------------------- - JustSimplePatrol - -------------------------*/
/*------------------------------- - by R0T - -------------------------------*/
/*--------------------------------------------------------------------------*/


//Chance her if you want them to wait longer or shoorter on the Waypoint.
_randomWait = 10; 


/*-----------------------DON'T TOUCH ANYTHING FROM HER-----------------------*/


private ["_Pat","_PatrolArea","_posNew","_PatGroup","_wait","_arrayLaenge","_ranStart","_firstRun","_BlackListArea","_thisArray","_WPointMarkerName","_PatrolMarker"];

_thisArray		= _this;			// Um später die Blacklist raus zu filtern	
_arrayLaenge 	= count _this; 
_Pat 			= _this select 0;
_PatGroup 		= group _Pat;
_PatrolArea		= _this select 1;
_PatrolMarker	= "";				// Für DEBUG
_WPointMarkerName = "";				// Für DEBUG

_wait 			= false;			
_firstRun 		= true;
_ranStart		= false;

_posNew			= [];	
_waterPos		= 0;				// Siehe SHK_pos und Wasserpositionen

_KindOfMan = _Pat isKindOf "Man";
_KindOfCar = _Pat isKindOf "Car";
_KindOfAir = _Pat isKindOf "Air";

//Standart behavior
	_Pat setBehaviour 	"SAFE";
	_Pat setSpeedMode 	"LIMITED";
	_Pat setCombatMode 	"RED";
	_Pat setFormation 	"LINE";



if (_arrayLaenge > 2) then 
{
 // Set Patrols behavior
	if ("CARELESS" 	in _this) then {_Pat setBehaviour "CARELESS";
									_thisArray = _thisArray - ["CARELESS"]};	
	if ("SAFE" 		in _this) then {_Pat setBehaviour "SAFE";
									_thisArray = _thisArray - ["SAFE"]};
	if ("AWARE" 	in _this) then {_Pat setBehaviour "AWARE";
									_thisArray = _thisArray - ["AWARE"]};
	if ("COMBAT" 	in _this) then {_Pat setBehaviour "COMBAT";
									_thisArray = _thisArray - ["COMBAT"]};
	if ("STEALTH" 	in _this) then {_Pat setBehaviour "STEALTH";
									_thisArray = _thisArray - ["STEALTH"]};

 // Set Formation "LINE"
	if ("COLUMN"		in _this) then {_Pat setFormation "COLUMN";
										_thisArray = _thisArray - ["COLUMN"]};	
	if ("STAG_COLUMN" 	in _this) then {_Pat setFormation "STAG COLUMN";
										_thisArray = _thisArray - ["STAG COLUMN"]};
	if ("ECH_LEFT"		in _this) then {_Pat setFormation "ECH LEFT";
										_thisArray = _thisArray - ["ECH LEFT"]};
	if ("ECH_RIGHT" 	in _this) then {_Pat setFormation "ECH RIGHT";
										_thisArray = _thisArray - ["ECH RIGHT"]};
	if ("VEE" 			in _this) then {_Pat setFormation "VEE";
										_thisArray = _thisArray - ["VEE"]};
	if ("LINE" 			in _this) then {_Pat setFormation "LINE";
										_thisArray = _thisArray - ["LINE"]};

 //Set Patrols speed
	if ("LIMITED" 	in _this) then {_Pat setSpeedMode "LIMITED";			//"LIMITED" (half speed)
									_thisArray = _thisArray - ["LINE"]};
	if ("NORMAL" 	in _this) then {_Pat setSpeedMode "NORMAL";				//"NORMAL" (full speed, maintain formation)
									_thisArray = _thisArray - ["NORMAL"]};
	if ("FULL" 		in _this) then {_Pat setSpeedMode "FULL";				//"FULL" (do not wait for any other units in formation)
									_thisArray = _thisArray - ["FULL"]};

 // Set Patrols CombatMode 
	if ("BLUE" 		in _this) then {_Pat setCombatMode "BLUE";				//"BLUE" (Never fire)
									_thisArray = _thisArray - ["BLUE"]};
	if ("GREEN" 	in _this) then {_Pat setCombatMode "GREEN";				//"GREEN" (Hold fire - defend only)
									_thisArray = _thisArray - ["GREEN"]};
	if ("WHITE" 	in _this) then {_Pat setCombatMode "WHITE";				//"WHITE" (Hold fire, engage at will)
									_thisArray = _thisArray - ["WHITE"]};
	if ("YELLOW" 	in _this) then {_Pat setCombatMode "YELLOW"; 			//"YELLOW" (Fire at will)
									_thisArray = _thisArray - ["YELLOW"]};
	if ("RED" 		in _this) then {_Pat setCombatMode "RED";				//"RED" (Fire at will, engage at will)
									_thisArray = _thisArray - ["RED"]};

 // Andere Parameter	
	if ("WAIT" 		in _this) then 	{_wait = true; _thisArray = _thisArray - ["WAIT"]};
	if ("RANDOM"	in _this) then 	{_ranStart = true; _thisArray = _thisArray - ["RANDOM"]};	

};	

// Liste mit BlackListArea's fertig machen	 
_thisArray = _thisArray - [_Pat,_PatrolArea];	// Einheit und PatrolArea rausnehmen 
_BlackListArea	= _thisArray;

// Einheit zum Start teleportieren wenn "RANDOM"
if (_ranStart) then 
{
  if (_KindOfMan) then 
	{
		_ranStartPos =[_PatrolArea,_waterPos,_BlackListArea] call SHK_pos;										
		{
		_x setPos _ranStartPos;
		}forEach units _PatGroup;
	};
  if (_KindOfCar) then 
	{
		_ranStartPos =[_PatrolArea,_waterPos,_BlackListArea] call SHK_pos;										
		_Pat setPos _ranStartPos;			
	}
};


if (_KindOfMan) then 
{

while 	{({alive _x} count units _PatGroup) > 0} do
	{
	if (_firstRun) then 
		{
		_posNew = [_PatrolArea,_waterPos,_BlackListArea] call SHK_pos;
		_Pat move _posNew;
		_firstRun = false;
		};

	if (((getPos leader _Pat)distance _posNew)< 5) then 
		{
		if (_wait) then 
			{
			sleep (floor(random _randomWait));
			_posNew = [_PatrolArea,_waterPos,_BlackListArea] call SHK_pos;
			_Pat move _posNew;
			} 
			else 
			{ 
			_posNew = [_PatrolArea,_waterPos,_BlackListArea] call SHK_pos;
			_Pat move _posNew;
			};
		};
		sleep 1;
	};
};

if (_KindOfCar) then 
{

while 	{({alive _x} count units _PatGroup) > 0} do
	{
	if (_firstRun) then 
		{
		_posNew = [_PatrolArea,_waterPos,_BlackListArea] call SHK_pos;

		_Pat move _posNew;
		_firstRun = false;
		};

	if (((getPos leader _Pat)distance _posNew)< 35) then 
		{
		if (_wait) then 
			{
			sleep (floor(random _randomWait));
			_posNew = [_PatrolArea,_waterPos,_BlackListArea] call SHK_pos;
			_Pat move _posNew;
			} 
			else 
			{ 
			_posNew = [_PatrolArea,_waterPos,_BlackListArea] call SHK_pos;
			_Pat move _posNew;
			};
		};
		sleep 1;
	};
};

if (_KindOfAir) then 
{
_waterPos		= 1; 		//Allow Waterpositions in SHK_pos		
while 	{({alive _x} count units _PatGroup) > 0} do
	{
	if (_firstRun) then 
		{
		_posNew = [_PatrolArea,_waterPos,_BlackListArea] call SHK_pos;
		_Pat move _posNew;
		_firstRun = false;
		};

	if (((getPos leader _Pat)distance _posNew)< 150) then 
		{
		if (_wait) then 
			{
			sleep (floor(random _randomWait));
			_posNew = [_PatrolArea,_waterPos,_BlackListArea] call SHK_pos;
			_Pat move _posNew;
			} 
			else 
			{ 
			_posNew = [_PatrolArea,_waterPos,_BlackListArea] call SHK_pos;
			_Pat move _posNew;
			};
		};
		sleep 1;
	};
};

every help would be awsome .... thx in advance;)

Edited by R0T

Share this post


Link to post
Share on other sites

Try adding this at the beginning:

waitUntil {!isNil "SHK_pos"};

I assume the error occurs because it tries to get a position from SHK_pos, before that function is initialized.

Share this post


Link to post
Share on other sites

Hey Tajin thx allot that fixes my prob. I thought the init.sqf would be faster then the init field of a unit. But hey new stuff learned - CHECK :D

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  

×