Warcraft III resources & community, 2003–2006 · archived

Conditions with parameters

3 posts
#1

Conditions with parameters

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

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:

function RepelActivationConditions takes player A returns boolean


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

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


- does not compile :(

Any tricks or ideas?
#2
allright, this is called The JASS way to do it...

    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.
#3
Thanks :) - pretty obvious to do it manually actually :oops: