• 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.

[JASS] Conditions with parameters

Status
Not open for further replies.
Level 2
Joined
May 1, 2006
Messages
4
Heya :)

I'm relatively new to GUI/JASS but I've gotten over the majority of initial hurdles. Something that has me stumped since yesterday, though, has cropped up that I've been trying to resolve (the current solution has to make use of a global, which I'm trying to avoid).

JASS:
function RepelActivationConditions takes nothing returns boolean
    ..simplified..
    elseif (IsUnitAlly(GetFilterUnit(), GetOwningPlayer(udg_RepelTrap)) == true) then
        return false
    elseif     ..simplified..
    endif
    return true
endfunction

The actual condition is called to match units in range to particular criteria. The matching occurs after initial waiting, so GetTriggerUnit and the like should be unavailable. How can I pass the unit or owning player along to the condition-function without making use of a global?

I've tried:

JASS:
function RepelActivationConditions takes player A returns boolean

But I haven't found a way to call it -

JASS:
set g = GetUnitsInRangeOfLocMatching(150.00, l, Condition(function RepelActivationConditions(A)))

- does not compile :(

Any tricks or ideas?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
allright, this is called The JASS way to do it...

JASS:
    local group g = CreateGroup()
    local unit u
    call GroupEnumUnitsInRangeOfLoc( g, l, range, null )
    loop
        set u = FirstOfGroup( g )
        exitwhen u == null
        if Condition then
            actions
        endif
        call GroupRemoveUnit( g, u )
        set u = null
    endloop
    call DestroyGroup( g )
    set g = null

Coincidentally, this also avoids the use of the extremely leaky ForGroup() function.
 
Status
Not open for further replies.
Top