HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Jass Help

08-27-2007, 09:12 AM#1
The Elite
Hi,
Im trying to make a function that instead of having to use a player group to kill multiple units i can just type one line of code. eg.
Collapse JASS:
    call KillUnits(udg_Thrall, a, b, udg_Jike)
but i can figure out how to do it. To be more specific i cant figure out how to do anything. By the way i'm a complete noob at jass and this is just for education and maybe will use it. Thanks in advance
08-27-2007, 03:33 PM#2
Vexorian
I don't understand, why di you have to use a player group to kill multiple units?
08-27-2007, 04:17 PM#3
Pytho
It can't be done in the way you want it (if I understand you), because functions in jass have a fixed number of arguments, there aren't optional arguments or something, so the only way you can do this is to write the function for any needed number of arguments.
e.g.:
Hidden information:

Collapse JASS:
function Kill2Units takes unit u1, unit u2 returns nothing
call KillUnit(u1)
call KillUnit(u2)
endfunction

function Kill3Units takes unit u1, unit u2, unit u3 returns nothing
call KillUnit(u1)
call KillUnit(u2)
call KillUnit(u3)
endfunction

function Kill4Units takes unit u1, unit u2, unit u3, unit u4 returns nothing
call KillUnit(u1)
call KillUnit(u2)
call KillUnit(u3)
call KillUnit(u4)
endfunction


So there isn't really an advantage to:
Collapse JASS:
call KillUnit(udg_Thrall)
call KillUnit(a)
call KillUnit(b)
call KillUnit(udg_Jike)
(And you also don't need a unit group to do it this way)
08-27-2007, 10:06 PM#4
The Elite
oh damit, ty anyway
08-27-2007, 11:54 PM#5
NightBreeze
You could do this:

Collapse JASS:
struct UnitCollection
    unit array units[50]
    integer amount

    static method Kill takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i == this.amount
            etcetc kill unit this.units[i]
            set i = i + 1
        endloop
    enmethod
endstruct

function SpellThatKillsUnits takes something returns something
    local UnitCollection uc = UnitCollection.create()
    local integer amount = 3                //The amount of units you're gonna kill in this spell

    ...

    set uc.units[0] = Unit 1 //wherever you get it.
    set uc.units[1] = Unit 2 //wherever you get it.
    set uc.units[2] = Unit 3 //wherever you get it.
    set uc.amount = 3        //3 units!
    call uc.Kill()
endfunction


And you would have a completely useless home-made unit group!
08-28-2007, 02:00 AM#6
Pyrogasm
You could also do it by making a function that takes 5 unit arguments but passing some of them as null if you didn't need to kill 5 units but 3.
08-28-2007, 07:02 AM#7
The Elite
Pyro, your a genius NO ONE TELL ME HOW TO DO THAT I NEED THE PRACTICE