HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Structures and timers

02-18-2009, 08:12 PM#1
APXEOLOG
I've heard that i can't create timer in structures, is it true?

I've got code now and it give me Syntax Error
Collapse JASS:
    public method StartCD takes nothing returns nothing
        set CDT = CreateTimer()
        set TCount = 0 
        call TimerStart( CDT, 0.1, true, method OnTimer)
        set CDT null
    endmethod
    
    private method OnTimer takes nothing returns nothing
        set TCount = TCount + 1
        if (TCount*10 >= CD) then
            call DestroyTimer(CDT)
            set IsRe = true
        endif
    endmethod

on line call TimerStart( CDT, 0.1, true, method OnTimer)
How can i make it right?
02-18-2009, 10:47 PM#2
Vexorian
Quote:
I've heard that i can't create timer in structures, is it true?
Quote:
on line call TimerStart( CDT, 0.1, true, method OnTimer)
You can only run a timer on static methods, and the syntax is function structname.methodname
The only way to do what you want is to use some sort of thing to attach the struct to the timer. Like TimerUtils,
02-19-2009, 12:06 AM#3
Anitarf
Also, set CDT null should be set CDT = null.
02-19-2009, 12:40 AM#4
TriggerHappy
From the current code, CDT is undeclared.

Though i'm guessing you didn't post the whole code, so yea, static methods.
02-19-2009, 11:49 AM#5
APXEOLOG
So i have trouble with structure =(

Collapse JASS:
struct Test
 real A
 real B
 
 method mTest takes nothing returns nothing
  set A = A + B
 endmethod
endstruct

I have error on line set A = A + B

When i try set this.A = this.A + this.B or set Test.A = Test.A + Test.B i got error too... what's wrong?
02-19-2009, 12:36 PM#6
Vexorian
Collapse JASS:
struct Test
 real A
 real B
 
 method mTest takes nothing returns nothing
  set this.A = this.A + this.B
 endmethod
endstruct
02-19-2009, 02:36 PM#7
Zerzax
Regular methods are dynamic - they have to manipulate the members of a specific instance (e.g. call instance.mTest(), pertains specifically to "instance"). You could accomplish your example by making A and B static members and manipulate them in a static method.
02-19-2009, 03:25 PM#8
xombie
The only time you would use "Test.something" in that situation would be if it was a static member. Static members are referred to using the struct name followed by '.' followed by the name of the member.