ForGroup calls in struct methods

Xbing

New Member
Reaction score
0
this is vjass. I have a method that needs a local group that picks units within range of location and i need it to have conditions. unfortunately, the function asks for a boolexpr and as far as i know a function is needed for a boolexpr(i tried using method but got a syntax error instead), and i need to use the struct's contents for the condition, and functions cannot be declared in structs (i tried doing so before), so im stuck now as i have many structs in the map and i wont be able to recall a specific struct in the function. any idea how to do it?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
It's simple to use a global integer variable. Or you could just write a short wrapper:

JASS:
library ForEach

    function interface callback takes integer data returns nothing

    globals
        private integer data
        private callback cb
    endglobals

    private function ForEachEnum takes nothing returns nothing
        call cb.execute(data)
    endfunction

    function ForEach takes group g, callback whichCB, integer dat returns nothing
        set data = dat
        set cb = whichCB
        call ForGroup(g,function ForEachEnum)
    endfunction
endlibrary

//USAGE:

//Instead of:
//call ForGroup(g,function BlahBlahBlah)
//Do
//call ForEach(g,callback.BlahBlahBlah,data)


The only problem is that it requires the Enum function to 'take' an integer. You could also modify my wrapper to use only one 'GetEnumUnit' call per unit.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top