vJASS methods as function code

Kajik

New Member
Reaction score
4
Hello,
I wonder if there is a way to pass struct methods as function code it TriggerAddAction(). There is an example:
JASS:

struct someStruct
   local trackable track

   method structMethod takes nothing returns nothing
      // do some stuff here
   endmethod

   method structInit takes nothing returns nothing
      local trigger t = CreateTrigger()
      set this.track = someRandomTrack // just an example
      call TriggerRegisterTrackableHitEvent(t, track)
      call TriggerAddAction(t, function this.structMethod)
   endmethod
endstruct

This syntaxe doesn't work, because real name of this method is something like s__someStruct_structMethod, but
JASS:

call TriggerAddAction(t, function s__someStruct_structMethod)

doesn't work either, because methods automaticaly requres integer paramether "this" and function must not take any arguments when used as code.

Any solutions???
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
AFAIK [lJASS]thistype.structMethod[/lJASS] should work.

[lJASS]call TriggerAddAction(t, function thistype.structMethod)[/lJASS]

Or you can use the name of the struct

[lJASS]call TriggerAddAction(t, function someStruct.structMethod)[/lJASS]
 

Kajik

New Member
Reaction score
4
JASS:

   method structMethod takes nothing returns nothing


It must be static method.

Thans to both of you, it worked. But now, how can I call non-static methods in static method?
JASS:

struct someStruct
    method calledMethod takes nothing returns nothing
        // do some stuff here
    endmethod
    
    static method statMethod takes nothing returns nothing
        call someStruct.calledMethod()
    endmethod
endstruct

(This doesn't work...)
 

Romek

Super Moderator
Reaction score
964
You can only call instance (non-static) methods if you actually have a struct instance.
 
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