Was inspired when I saw the example.: Using a method as the timer subroutine ( SetTimer ).
Code: Select all
; Example #4: Using a method as the timer subroutine.
counter := new SecondCounter
counter.Start()
Sleep 5000
counter.Stop()
Sleep 2000
; An example class for counting the seconds...
class SecondCounter {
__New() {
this.interval := 1000
this.count := 0
; Tick() has an implicit parameter "this" which is a reference to
; the object, so we need to create a function which encapsulates
; "this" and the method to call:
this.timer := ObjBindMethod(this, "Tick")
}
Start() {
; Known limitation: SetTimer requires a plain variable reference.
timer := this.timer
SetTimer % timer, % this.interval
ToolTip % "Counter started"
}
Stop() {
; To turn off the timer, we must pass the same object as before:
timer := this.timer
SetTimer % timer, Off
ToolTip % "Counter stopped at " this.count
}
; In this example, the timer calls this method:
Tick() {
ToolTip % ++this.count
}
}
1. From the example - is it difficult to get this.count in a variable?
(something like this)
Code: Select all
counter := new SecondCounter
counter.Start()
Sleep 3000
TimeHold := counter.Tick()
MsgBox % TimeHold
Sleep 3000
counter.Stop()
Sleep 2000
ExitApp
(something like this)
Code: Select all
counter := new SecondCounter
counter.Start()
Loop
{ ; some instructions
;
; This compare should be somewhere else
; If counter.Tick() > 3
; Break
;
; some instructions
}
ExitApp