• 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 inside struct?

Status
Not open for further replies.
Level 4
Joined
Feb 2, 2009
Messages
71
I have a problem with structs. An example might come handy:
JASS:
function SomeFilter takes nothing returns boolean
     return SomeCondition
endfunction

struct someStruct
     unit u
     group g

     method someMethod takes nothing returns unit
          local someStruct some
          local filterfunc filter = Filter(function SomeFilter)
          call GroupEnumUnitsInRect(some.g, bj_mapInitialPlayableArea, filter)
          set some.u = FirstOfGroup(g)
     endmethod
endstruct
The above script does not generate any error, but no unit gets filtered and the code stops.
Maybe you're not able to call functions from inside a struct?

I've tried this way (below) too, but it doesn't work either.
JASS:
struct someStruct
     unit u
     group g

     method someFilter takes nothing returns boolean
          return someCondition
     endmethod

     method someMethod takes nothing returns unit
          local someStruct some
          local filterfunc filter = Filter(some.SomeFilter) //Syntax Error
          call GroupEnumUnitsInRect(some.g, bj_mapInitialPlayableArea, filter)
          set some.u = FirstOfGroup(some.g)
     endmethod
endstruct

Tried this too but it also generates syntax error.
JASS:
local filterfunc filter = Filter(method some.SomeFilter)

...and also:
JASS:
local filterfunc filter = Filter(function some.SomeFilter)

What is the proper way to do it?
 
Level 4
Joined
Feb 2, 2009
Messages
71
...and question 2.

Can I make a struct accessible from another trigger?
I tried
JASS:
public struct whatEver

But when I call it from another trigger it says "Undefined type whatEver".
Maybe if I put the struct in a library or something?
 

peq

peq

Level 6
Joined
May 13, 2007
Messages
171
Make SomeFilter a static method and then use
JASS:
local boolexpr filter = Condition(function some.SomeFilter)

A struct can be used anywhere by default unless its private or private per keyword. Are you using latest JassHelper?
 
Level 4
Joined
Feb 2, 2009
Messages
71
Got it to work now. Thank you.

I had to use someStruct and not some to get it to work.
Also SomeMethod had to be static too.

JASS:
local filterfunc filter = Filter(function someStruct.SomeFilter)

Is there any difference between boolexpr and filterfunc?
It seems to me like they work the same way.

Same goes with Condition(...) and Filter(...).
---
A struct can be used anywhere by default unless its private or private per keyword. Are you using latest JassHelper?
Hmm, I use JassHelper 0.9.E.0, the newest seem to be 0.9.F.0.

I still have problem with using the struct from outside the trigger (another trigger).
You think it will help if I update JassHelper?
 
Level 11
Joined
Apr 6, 2008
Messages
760
JASS:
scope Blah

globals
    private boolexpr Bool
endglobals

private struct Data

   // Stuff...

   static method onInit takes nothing returns nothing
       set Bool = Condition(function UnitFilter)
   endmethod

   static method UnitFilter takes nothing returns boolean
   //filter stuff
   endmethod

endstruct

endscope

better to use globals, then u dont need to save it each time u run the somefilter function
 
Status
Not open for further replies.
Top