Spriterfight 10 Posted August 2, 2020 So i have this: while {alive _gunner} do { _list = nearestObjects [_gunner,["Man"],400]; _listfiltered = _list select {side _x == EAST}; if (count _listfiltered > 0) then { _target = _listfiltered select 0; } else { _target = nil; ); if (_target distance _gunner < 400) then { //gives an error at this line it gives me an error that undefined variable in expression _target but i defined if the unit is in the radius of gunner then t will be _listfiltered select 0; but i dont understand that ,how can i bypass this ?should a _target = nil; work in the else statement?I tried with private _target = nil; before the while loop but didnt work Share this post Link to post Share on other sites
Spriterfight 10 Posted August 2, 2020 How should i skip these error if i have an local variable that will be defined in a if statement ? it works if one of east units are within the radius but if there are none then its gives me an error.Tried this ,dosent work; while {alive _gunner} do { _list = nearestObjects [_gunner,["Man"],400]; _listfiltered = _list select {side _x == EAST}; private _target = nil; if (count _listfiltered > 0) then { private _target = _listfiltered select 0; }; if (private _target distance _gunner < 400) then { Share this post Link to post Share on other sites
gc8 978 Posted August 2, 2020 (edited) The problem with the _target variable is because it's not defined in the loop scope but only in the lower scopes while {alive _gunner} do { _list = nearestObjects [_gunner,["Man"],400]; _listfiltered = _list select {side _x == EAST}; _target = objNull; // declare _target here! if (count _listfiltered > 0) then { _target = _listfiltered select 0; } else { //_target = nil; // No need for this ); changing to that should do the trick. the _target is now defined in the loop's scope Edited August 2, 2020 by gc8 removed = nil 1 Share this post Link to post Share on other sites
Spriterfight 10 Posted August 2, 2020 Oh thank you very much.Now it dosent gives me errors. Share this post Link to post Share on other sites