Use timer with struct methods

Homer

New Member
Reaction score
2
Is there a way to use TimerStart with a struct method?

JASS:
TimerStart(t,.01,true, this.method timeraction)


? thanks


Edit can som1 move this to jass? I accidently posted it here
 

Homer

New Member
Reaction score
2
This is what I put
JASS:
method init takes nothing returns nothing
        TimerStart(this.t,.01,true,this.Step)
    endmethod


This is where I get the syntax error(when its being compiled by jass helper)
JASS:
TimerStart(s__unitData_t[this] , .01 , true , unitData.getMethod(Step,this))
 

DrEvil

FCRI Associate!
Reaction score
111
You can only use static methods or function's for code parametres( same thing )

You will need a sort of atachment if you want to do it that way

Recieve the struct in the static method wtih a timer attachment
 

Homer

New Member
Reaction score
2
can you elaborate? I'm somewhat new to structs. What is a static method as oppose to other methods. And How I go about this?
 

saw792

Is known to say things. That is all.
Reaction score
280
You forgot 'call'.

A static method is just a regular function inside a method. The actions it performs apply to everything. A regular method only performs the actions on a specific struct instance.
 

DrEvil

FCRI Associate!
Reaction score
111
A static method is like a function.( But doesnt take a struct instance )
A method is called from the struct variable.

Using ABC it would be like :
JASS:
struct Data
   ...
   ...
   static method DoSomething takes nothing returns nothing
       local Data d = GetTimerStructA(GetExpiredTiemr())
       ... // No do what you want with the struct instance
   endmethod
endstruct

function acts takes nothing returns nothing
    local timer t = CreateTimer() // Or however
    local Data d = Data.create()
    call SetTimerStructA(t,d)
    call TimerStart(t,.01,true, Data.DoSomething)
endfunction



That is what you should aim for , learning about structs - timers .
How they work well

Hope i explained a bit more :)

EDIT : Beaten by the saw :p
 

DrEvil

FCRI Associate!
Reaction score
111
@T.S.E

A static method is a function.
Plus you need to give the struct name ( for the static method ) :

call TimerStart(t, 0.03, true, Wee.Callback)
 

Romek

Super Moderator
Reaction score
963
You still have to type the 'function' part you know..
JASS:
call TimerStart(... .. , Data.Method)

Will come up with an "Undeclared Variable" error.

JASS:
call TimerStart(... .. , function Data.Method)

Is more like it.
It has to be a static method that takes and returns nothing though.
 

Akolyt0r

New Member
Reaction score
33
the difference between static methods and non-static methods is basically you cant use the "this"-codeword in static methods.
And you cant use nonstatic methods in ForGroup, ForForce, or TimerCallbacks :)
 

Romek

Super Moderator
Reaction score
963
> cant use the "this"-codeword in static methods.
Yes you can. Only for static members though.

JASS:
struct eg
  static integer I = 0
  
  private static method Hello takes nothing returns nothing
     if this.I == .I then
        // Dunno. Obviously true though.
     endif
  endmethod

endstruct


Static methods are just like ordinary functions otherwise.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top