Magentix
if (OP.statement == false) postCount++;
- Reaction score
- 107
I got this function, but I'm pretty sure that there's a way more efficient and OP limit-friendly version of it...
Checks for gaps up to a maximum of 10.
Since there will almost never be a gap greater than 10 at any given time, this should suffice, although very inefficient...
Anyone got a better idea?
For those of you who may doubt:
- Reason this is inneficient is because if somewhere there's a gap of, let's say, 8: it will loop those 8 times through the gaps every time until everything has shuffled to the left.
- Secondly, a series like this: UnnUnnnnUnnnnnnnUnnnnU (U = Unit, n = null),
would quickly result in UUUnnnnnnnnnnnnnUnnnnU, halting the loop when it shouldn't.
JASS:
private function SortUnitArray takes nothing returns nothing
local integer i=1
local integer gap=0
local integer goodUnits=0
loop
exitwhen gap >= 10
if UNITS<i>==null then
set gap=gap+1
else
if gap>0 then
set UNITS[i-gap] = UNITS<i>
set UNITS<i> = null
endif
set good_units=goodUnits+1
set gap=0
endif
set i=i+1
endloop
set totalUnitsInArray = goodUnits
endfunction</i></i></i>
Checks for gaps up to a maximum of 10.
Since there will almost never be a gap greater than 10 at any given time, this should suffice, although very inefficient...
Anyone got a better idea?
For those of you who may doubt:
- Reason this is inneficient is because if somewhere there's a gap of, let's say, 8: it will loop those 8 times through the gaps every time until everything has shuffled to the left.
- Secondly, a series like this: UnnUnnnnUnnnnnnnUnnnnU (U = Unit, n = null),
would quickly result in UUUnnnnnnnnnnnnnUnnnnU, halting the loop when it shouldn't.