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

Filter(struct)

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
Im trying to do

call TriggerAddCondition(t, Filter(this.add))

but it keeps telling me that "this is not an struct name)

if i do thistype.add it asks for a static method but i dont want to pass a static method...
 
You have no choice, a filter function must be a function that takes nothing and returns boolean. However, non-static method are replaced by functions that take at least 1 argument ("this" is an argument in the compiled jass code).

You have to use a handle-link system (such as an hashtable but there are better ones around there), to link your structure instance to the trigger :
JASS:
struct Smth

    unit u
    static hashtable TheHash = InitHashtable()

    static method add takes nothing returns boolean
        local thistype this = LoadInteger(TheHash, GetTriggeringTrigger(), 0)
        return IsUnitType(this.u, UNIT_TYPE_DEAD)
    endmethod

    static method create takes unit whichUnit returns thistype
        local thistype this = thistype.allocate()
        local trigger t = CreateTrigger()
        set this.u = whichUnit
        call SaveInteger(TheHash, t, 0, this)
        call TriggerAddCondition(t, Filter(thistype.add))
        // etc...
    endmethod

endstruct
That's just a sample.
 
Level 15
Joined
Feb 15, 2006
Messages
851
Im trying to do

call TriggerAddCondition(t, Filter(this.add))

but it keeps telling me that "this is not an struct name)

if i do thistype.add it asks for a static method but i dont want to pass a static method...

call TriggerAddCondition(t, Filter(<struct name>.add))

In this way it will work...

this and thistype are keywords that only work INSIDE the struct, not outside of it.
 
Status
Not open for further replies.
Top