Jump to content
Sign in to follow this  
shifty_ginosaji

Problems with undefined variables when getting variable from array

Recommended Posts

I am working on a jamming script and there is an "error: undefined variable" on line 23 {_missile setDir _missileVector} even though it was defined on line 21 {_missileArray (getpos_jammer) nearEntities["M_Titan_AA_long",_jamRange];}?

I have no idea whats going on, please help?

//
//Syntax:
//
// _null = [Jammer,Jammer Range] execVM "jammer-missiledetection.sqf";
//
//

waituntil {!isnil "bis_fnc_init"};

_jammer = _this select 0;
_jamRange = _this select 1;
_jammerOn = "true";

private ["_jammer","_jamRange","_missileVector","_missileArray","_missile"];

while {_jammerOn == "true"} do {

	player sideChat "This debug proves the while-do construct is working";
       _missileVector = round(random 360);	
       _missileArray = (getpos _jammer) nearEntities ["M_Titan_AA_long",_jamRange];
	sleep 0.01;
       _missile = _missileArray select 0;	
       _missile setDir _missileVector;
	sleep 0.2;

};


Edited by Madopow2110

Share this post


Link to post
Share on other sites

Where is the hash symbol ( # ) in your error message?

---------- Post added at 03:04 ---------- Previous post was at 02:57 ----------

Well I went through it and made a couple of changes, using variables before you "private" them has an unknown effect (to me, never tried that before), so try it this way (you can remove my comments)

waituntil {!isnil "bis_fnc_init"};

private ["_jammer","_jamRange","_missileVector","_missileArray","_missile"]; //define variables before using them

_jammer = _this select 0;
_jamRange = _this select 1;
_jammerOn = true; //no need for string

while {_jammerOn} do {

	hintSilent "This debug proves the while-do construct is working"; //no more side chat spam!
	_missileVector = round(random 360);	
	_missileArray = (getpos _jammer) nearEntities ["M_Titan_AA_long",_jamRange];
	sleep 0.01;
	_missile = _missileArray select 0;	
	_missile setDir _missileVector; //setDir kills velocity so you should save velocity, then reapply it in the correct vector
	sleep 0.2;

};

hintSilent ""; //close the "hint" display as soon as the loop ends

Share this post


Link to post
Share on other sites

thanks for the work, as for you comments the hash was in front of the _missile in the setdir line. setdir in previous tests is fine for these purposes so no velocity vector is needed

EDIT: (#) _missile setDir _missileVector;

is still broken in the undefined variable error

Share this post


Link to post
Share on other sites

Your missileArray is empty and you are returning element 0 which doesnt exist. Either add check if array is empty or use foreach loop

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  

×