nullsystems 0 Posted December 5, 2007 Ello, Question really quick... How do you find the smallest number in an array? _array = [a,b,c,d] ...told you it was quick lol. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> t1 = massy distance player t2 = moddy distance player t3 = eppy distance player t4 = baggy distance player _Array = [t1,t2,t3,t4]; _startNum = 900000; _select = 0; _find = 0; _maxcount = count _Array; #loop _num = (_Array select _select) ?(_num < _startNum) : _Distance = _num; _startNum = _num _select = _select + 1 ?_select < _maxcount: goto "loop" I did have it working but I think I broke it, it always returns the last value in the array, not the smallest  Thank you ! Share this post Link to post Share on other sites
nullsystems 0 Posted December 5, 2007 Aha! im a fool. ?(_num < _startNum) : _Distance = _num; _startNum = _num ^ Should be: ?(_num < _startNum) : _Distance = _num; _startNum = _num There we go, quick lesson on finding the least distance to a player out of an array lol Share this post Link to post Share on other sites
zwobot 22 Posted December 5, 2007 Just loop through the array with a while. Assign the first element of the array as the smallest variable and compare each following element with the currently smallest element and update the smallest-value variable if necessary: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _smallest = _array select 0; _index = 0; while(_index < count(_array)) { if(_array select _index < _smallest) { _smallest = _array select _index; }; }; That should be it. Share this post Link to post Share on other sites
HitmanFF 6 Posted December 5, 2007 forEach will let you loop through an array very quickly. Something like<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_smallest = _array select 0; {if (_x < _smallest) {_smallest = _x;};} forEach _array; Share this post Link to post Share on other sites
nullsystems 0 Posted December 6, 2007 Funny how you can come up with so many solutions for one problem... Turns out they all worked in the end, even mine lol, thanks for the info guys. Share this post Link to post Share on other sites