• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] [Jass] Group get unit by index?

Status
Not open for further replies.
In JASS, what is the best way of getting a unit from a group by index?

Is it even possible without shuffleing units to a temp-group and back to the original group again (like the following)?

JASS:
function groupGetUnitByIndex takes group g, integer index returns unit
    local integer i = 0
    local group tempGroup = CreateGroup()
    local unit u
    local unit returnUnit = null
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        if i == index then
            set returnUnit = u
        endif
        set i = i + 1
        call GroupRemoveUnit(g,u)
        call GroupAddUnit(tempGroup, u)
    endloop
    loop
        set u = FirstOfGroup(tempGroup)
        exitwhen u == null
        call GroupRemoveUnit(tempGroup,u)
        call GroupAddUnit(g, u)
    endloop
    call DestroyGroup(tempGroup)
    set tempGroup = null
    return returnUnit
endfunction

It is possible to have a copy of the group as an array I guess...
 

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
539
If you're on a patch 1.31 or later you can use
JASS:
native BlzGroupUnitAt takes group whichGroup, integer index returns unit
 
Status
Not open for further replies.
Top