How to use a method?

Reaction score
456
First of all, put the static methods inside a structure.

call TimerStart(.tim, 0.04, true, <structname>.<methodname>)

In this case it would be hello.periodic. You have to do what I said first, though.
 

Flare

Stops copies me!
Reaction score
662
1) Static methods must be within the struct declaration e.g.
JASS:
struct Test

static method TestStatic takes nothing returns nothing
endmethod

endstruct


2) Static methods are called by prefixing the method name with the struct's name and a period e.g.
JASS:
//for the above struct
call Test.TestStatic ()


For your example, it'd be
JASS:
call TimerStart (whichTimer, interval, periodicBool, function hello.periodic

Assuming you placed the periodic method in the hello struct
 

Tom Jones

N/A
Reaction score
437
JASS:
struct main
     static method onCast_Conditions takes nothing returns boolean
         return ...
     endmethod

     static method onCast takes nothing returns nothing
         ...
     endmethod

     static method onInit takes nothing returns nothing
         local trigger trig = Create Trigger()

         call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_SPELL_EFFECT)
         call TriggerAddCondition(trig,function thistype.onCast_Conditions)
         call TriggerAddFunction(trig,function thistype.onCast)
    endmethod
endstruct

//Alternatively:
private function Init takes nothing returns nothing
         local trigger trig = Create Trigger()

         call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_SPELL_EFFECT)
         call TriggerAddCondition(trig,function main.onCast_Conditions)
         call TriggerAddFunction(trig,function main.onCast)
endfunction
 

Tom Jones

N/A
Reaction score
437
Static methods can easily be private, it however disables access to the method from outside the struct.

JASS:
local thistype this
should always be used inside a struct, at least in my opinion. Are you wondering what you should assign as value?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
JASS:
local thistype this
should always be used inside a struct, at least in my opinion. Are you wondering what you should assign as value?

I've heard the opposite, that it should only be used inside a module. I understand that it makes renaming a struct easier, but I find the syntax to be a bit disorganized. Vexorian himself said that you COULD, but that he personally thinks it's not something he'd ever do.

Also:

JASS:
private function Init takes nothing returns nothing
         local trigger trig = Create Trigger()

         call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_SPELL_EFFECT)
         call TriggerAddCondition(trig,function main.onCast_Conditions)
         call TriggerAddFunction(trig,function main.onCast)
endfunction


this function only runs on initialization if it is inside a scope/library that defines it to be the initializer. Like so:

JASS:
library arbitrary initializer Init

private function Init takes nothing returns nothing
         local trigger trig = Create Trigger()

         call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_SPELL_EFFECT)
         call TriggerAddCondition(trig,function main.onCast_Conditions)
         call TriggerAddFunction(trig,function main.onCast)
endfunction

endlibrary
 

quraji

zap
Reaction score
144
But I find it kinda useless, it takes more time than a normal function...

First of all, you don't need to create an instance of a struct to use it static methods. Just use 'StructName.StaticMethodName()'.

Next, if you plan on using it as a regular function outside the struct, just use a normal function. The point of static methods is to contain functions inside the struct, for use with the struct.
 
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