• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Picking highest HP target in range?

Status
Not open for further replies.
Level 2
Joined
Apr 7, 2009
Messages
8
this is what i got, is it anywhere near right? :)
JASS:
        loop
            set First = FirstOfGroup(Hate)
                if ((GetWidgetLife(First)) >= hp) then
                set HpHigh = First
                set hp = (GetWidgetLife(First))
                call GroupRemoveUnit(Hate, First)
                elseif ((GetWidgetLife(First)) < hp) then
                call GroupRemoveUnit(Hate, First)
                endif 
        exitwhen (First == null)
        endloop
 
Level 5
Joined
Dec 18, 2007
Messages
205
the code will work, but for some performance just make

JASS:
loop
    set First = FirstOfGroup(Hate)
    exitwhen First == null
    if GetUnitState(First, UNIT_STATE_LIFE) >= hp then
        set HpHigh = First
        set hp = (GetWidgetLife(First))
    endif
    call GroupRemoveUnit(Hate, First)
endloop

this way you exit the loop directly if there is no unit and you also don't need to check if the unit has less hp than the one that was picked because ithat's the thing you don't need. and whether the if returns true or false: in both cases you remove the unit of the group, so you can just do that after the if.
you also may have recognized that i used GetUnitState(). i never tested GetWidgetLife(), so i used sth. i know.

greetings
 
Status
Not open for further replies.
Top