shifty_ginosaji 10 Posted October 9, 2014 (edited) 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 October 9, 2014 by Madopow2110 Share this post Link to post Share on other sites
dreadedentity 278 Posted October 9, 2014 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
shifty_ginosaji 10 Posted October 9, 2014 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
killzone_kid 1332 Posted October 9, 2014 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
shifty_ginosaji 10 Posted October 9, 2014 awesome, thanks for the help. also, if anybody knows how to detect chat msgs being sent please tell Share this post Link to post Share on other sites