Hey there!
Maybe because I'm tired, or for whatever reason... I'm stuck.
What I'm doing:
- Defining units as a global array unit called 'ATTACKER[15]'
- A unit's speed is important for this and is calculated in an other function (I'm leaving out of this) called GetUnitSpeed(unit).
- The unit group 'ATTACKERS' consists out of a maximum of 16 units, so that's why the array value of ATTACKER[15] has 15 as it's highest number.
- Eventually I want this loop to check the speed of all the units in the ATTACKERS group and sort them based on their speed. ATTACKER[0] will be the fastest unit, and ATTACKER[15] will be the slowest, based on my 'GetUnitSpeed(unit)' calculations.
Now my problem is:
I just noticed that with the current code the following scenario goes wrong:
- The last unit of the unit group is being checked (let's say this is the 16th unit) and he appears to be faster than all the other 15. Theoretically he should end up becoming ATTACKER[0] then, but with what I've made so far a unit will only shove up one spot so he will become ATTACKER[14] since 'i' was on 15, and I made him go to spot 'i-1'.
It might look simple, and it probably is... But my brain is broken and my headache blocks me from seeing the solution.
Is there anyone that wants to help me out or give me a hint to wake up my failing brains? I'd appreciate any help!
Thanks in advance.
Maybe because I'm tired, or for whatever reason... I'm stuck.
What I'm doing:
- Defining units as a global array unit called 'ATTACKER[15]'
- A unit's speed is important for this and is calculated in an other function (I'm leaving out of this) called GetUnitSpeed(unit).
- The unit group 'ATTACKERS' consists out of a maximum of 16 units, so that's why the array value of ATTACKER[15] has 15 as it's highest number.
- Eventually I want this loop to check the speed of all the units in the ATTACKERS group and sort them based on their speed. ATTACKER[0] will be the fastest unit, and ATTACKER[15] will be the slowest, based on my 'GetUnitSpeed(unit)' calculations.
JASS:
loop /// Grouping the Attackers
set u = FirstOfGroup(ATTACKERS)
exitwhen u == null
call GroupRemoveUnit(ATTACKERS, u)
set i = 0
loop
exitwhen i == 16 or u == ATTACKER[i-1]
if GetUnitSpeed(u) > GetUnitSpeed(ATTACKER[i-1]) and ATTACKER[i-1] != null and i > 0 then
set ATTACKER[i-1] = ATTACKER[i]
set u = ATTACKER[i-1]
else
set ATTACKER[i] = u
endif
set i = i + 1
endloop //Fastest unit will be ATTACKER[0] and from there on the higher numbers will go up. Slowest is ATTACKER[15]
endloop
Now my problem is:
I just noticed that with the current code the following scenario goes wrong:
- The last unit of the unit group is being checked (let's say this is the 16th unit) and he appears to be faster than all the other 15. Theoretically he should end up becoming ATTACKER[0] then, but with what I've made so far a unit will only shove up one spot so he will become ATTACKER[14] since 'i' was on 15, and I made him go to spot 'i-1'.
It might look simple, and it probably is... But my brain is broken and my headache blocks me from seeing the solution.
Is there anyone that wants to help me out or give me a hint to wake up my failing brains? I'd appreciate any help!
Thanks in advance.