• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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