I just started learning JASS and I'm trying to experiment with some code, and I wrote some script and it doesn't seem to work properly but it looks fine to my amateur eyes. It is supposed to kill every Nth unit in a unit group(integer n is a parameter) and it calls another function I wrote which I included but I don't think that's the problem. here's my code:
could someone help me improve my JASS and make it work properly? I really want to learn JASS!
JASS:
function GetNthOfGroup takes group g,integer i returns unit
local group g2 = g
local integer i2 = 0
loop
call GroupRemoveUnit(g,FirstOfGroup(g))
set i2 = i2 + 1
if( i2 == i )then
set i2 = 0
endif
exitwhen i2==0
endloop
return FirstOfGroup(g2)
endfunction
function KillEveryNthUnitInGroup takes group g, integer n, boolean removeUnits returns nothing
local group g2 = g
local integer i = CountUnitsInGroup(g)/(n-1)
local integer i2 = 0
local integer i3 = 0
set n = n-1
loop
exitwhen i2 > i
call KillUnit( GetNthOfGroup( g2, n ) )
call GroupRemoveUnit(g2, GetNthOfGroup(g2,n))
if( removeUnits == true) then
call GroupRemoveUnit( g, GetNthOfGroup(g2,n))
endif
loop
exitwhen i3 == n
call GroupRemoveUnit(g2,FirstOfGroup(g2))
set i3 = i3 + 1
endloop
set i2 = i2 + 1
endloop
endfunction