Ive been working on something for past day and half now and It worked perfectly except for this:
When I pick units to group and then I check owners, it works fine but when I try to sort it it ever freezes to the "intial value" until there are units only of one player.
Ive also tried:
now some examples:
lets say there is at map init 1 unit owned by Player 1(blue) at cpx[1], cpy[1] within radius[1], so the first time the winner is 1 as intended but if I rush it there with 3 units there are now 3 of mine, 1 of player 1(blue) so it should display 0 but it displays still 1 and only when all units of Player 2 are dead(in this case 1) it changes to 0
any help is appreciated
PS: this is not the whole trigger, the rest works as intended this is only part that doesnt work(the sorting) so dont worry about leaks or so
When I pick units to group and then I check owners, it works fine but when I try to sort it it ever freezes to the "intial value" until there are units only of one player.
JASS:
function Loop takes nothing returns boolean
local integer loop1 = 0
local integer array unitswithin
local unit first
local integer loop2 = 0
local texttag ttx
local group g = CreateGroup()
local integer winner
local integer mainloop = 1 //up to stack(global variable)
loop
call GroupClear(g)
call GroupEnumUnitsInRange(g, cpx[mainloop], cpy[mainloop], radius[mainloop], null)
//those are global arrays, this will loop trough all of them up to stack(another global)
loop
set first = FirstOfGroup(g)
exitwhen first == null
call GroupRemoveUnit(g, first)
if not IsUnitType(first, UNIT_TYPE_DEAD) then
set unitswithin[GetPlayerId(GetOwningPlayer(first))] = unitswithin[GetPlayerId(GetOwningPlayer(first))] + 1
endif
endloop
//now this is where the magic stops working
loop
set loop2 = loop1 + 1
loop
if unitswithin[loop1] < unitswithin[loop2] then
set winner = loop2
endif
debug call BJDebugMsg(I2S(winner))
exitwhen loop2 == 12
set loop2 = loop2 + 1
endloop
exitwhen loop1 == 11
set loop1 = loop1 + 1
endloop
exitwhen mainloop == stack
set mainloop = mainloop + 1
endloop
return false
endfunction
JASS:
//another:
loop
set loop2 = 0
loop
if unitswithin[loop1] < unitswithin[loop2] then
set winner = loop2
endif
call BJDebugMsg(I2S(winner))
exitwhen loop2 == 12
set loop2 = loop2 + 1
endloop
exitwhen loop1 == 11
set loop1 = loop1 + 1
endloop
//as well as
loop
set loop2 = loop1 + 1
loop
if unitswithin[loop1] < unitswithin[loop2] then
set winner = loop2
else
set winner = loop1
endif
call BJDebugMsg(I2S(winner))
exitwhen loop2 == 12
set loop2 = loop2 + 1
endloop
exitwhen loop1 == 11
set loop1 = loop1 + 1
endloop
lets say there is at map init 1 unit owned by Player 1(blue) at cpx[1], cpy[1] within radius[1], so the first time the winner is 1 as intended but if I rush it there with 3 units there are now 3 of mine, 1 of player 1(blue) so it should display 0 but it displays still 1 and only when all units of Player 2 are dead(in this case 1) it changes to 0
any help is appreciated
PS: this is not the whole trigger, the rest works as intended this is only part that doesnt work(the sorting) so dont worry about leaks or so