• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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