Timer in Module

Status
Not open for further replies.
Level 17
Joined
Mar 21, 2011
Messages
1,611
Hey guys,

i'm struggling with a (probably) very simple problem. I try to create a buff module that calls a method periodically. As long as i don't implement the module, JassHelper will compile, but as soon as i want to use it, it will throw an error: "this" is not a type that allows . syntax. I'm wondering why that is..

JASS:
    module Buff

        string icon
        string name
        string description
        real duration
        real interval
        // ...
        timer periodictimer
   
        static method callPeriodicBuff takes nothing returns nothing
            local thistype this = GetTimerData(GetExpiredTimer())
            call this.periodic()
        endmethod

        method onEnd takes nothing returns nothing
            // ...
        endmethod

        method onInterval takes nothing returns nothing
            // ...
        endmethod

        method onStart takes nothing returns nothing
            // ...
        endmethod

        method periodic takes nothing returns nothing
            // ...
        endmethod

        static method create takes nothing returns thistype
            local thistype this = thistype.allocate()
            set periodictimer = NewTimer()
            call SetTimerData(periodictimer, this)           
            call TimerStart(periodictimer, 0.1, true, function thistype.callPeriodicBuff)
            return this
        endmethod

        method destroy takes nothing returns nothing
            // ...
        endmethod



    endmodule

    /*struct s
        implement Buff
    endstruct*/
 
Level 17
Joined
Mar 21, 2011
Messages
1,611
first of all.. it worked!

second: is it possible to create those methods as an interface? I want to do

JASS:
module Buff
        method OnInterval takes nothing returns nothing
endmodule


struct s
    method onInterval takes nothing returns nothing
        // do something
    endmethod

    implement Buff
endstruct
 
But it should allow calling underlying methods with JassHelper just creating an extra method above behind the scenes.

JASS:
struct TestStruct

static method a takes nothing returns nothing
    local thistype this = 1
    call this.b()
endmethod

method b takes nothing returns nothing
endmethod

endstruct

.. compiled:

JASS:
//Generated method caller for TestStruct.b
function sc__TestStruct_b takes integer this returns nothing
endfunction

function s__TestStruct_a takes nothing returns nothing
    local integer this= 1
    call sc__TestStruct_b(this)
endfunction

function s__TestStruct_b takes integer this returns nothing
endfunction

.. where the very first function is onlycreated so one can call the underlying "b" function in source code from "a".

is it possible to create those methods as an interface?
Yeh, a struct can extend an interface JassHelper 0.A.0.0.
 
Level 17
Joined
Mar 21, 2011
Messages
1,611
yes that is basically what i want. it is a bit weird tho, to create methods in struct A and leave them empty like
JASS:
method onInterval takes nothing returns nothing
endmethod
it has to be declared due to the interface.. so.. is there a "better" way?
 
Status
Not open for further replies.
Top