We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't get LDTimers to work
#4
JR,

You are right that the LD version takes a little longer to get going - not quite sure why this is, but there is more code due to potentially several timers.

A continuous loop isn't needed, since SB stays running when TextWindow is open, so the following also work.

Code:
Name=LDTimer.Add()
LDTimer.Interval(Name,10)
LDTimer.Tick=OnTimerTick

Program.Delay(100)

Sub OnTimerTick
  TextWindow.WriteLine("Here")
EndSub

or

Code:
Name=LDTimer.Add()
LDTimer.Interval(Name,10)
LDTimer.Tick=OnTimerTick

TextWindow.WriteLine("Start")

Sub OnTimerTick
  TextWindow.WriteLine("Here")
EndSub

Each timer does use its own thread.  The following code trys to show how the different timers can be used.

Code:
'Original timer
Timer.interval= 1000
Timer.tick=OnTimerTick1

'2 Timers sharing an event subroutine
LDTimer.Tick=OnTimerTick2
Name1=LDTimer.Add()
LDTimer.Interval(Name1,500)
Name2=LDTimer.Add()
LDTimer.Interval(Name2,600)

'2 Timers on different event subroutines
Name3=LDTimer.Addtick("OnTimerTick3")
LDTimer.Interval(Name3,700)
Name4=LDTimer.Addtick("OnTimerTick4")
LDTimer.Interval(Name4,800)

Sub OnTimerTick1
  TextWindow.WriteLine("SB Timer1")
EndSub

'2 timers sharing subroutine, distinguished by LastTimer
Sub OnTimerTick2
  timer = LDTimer.LastTimer
  TextWindow.WriteLine("LD Timer2 "+timer)
EndSub

'Since these timers are on different subroutines they don't set LastTimer
Sub OnTimerTick3
  TextWindow.WriteLine("LD Timer3")
EndSub

Sub OnTimerTick4
TextWindow.WriteLine("LD Timer4")
EndSub

Just saw last post by WHTurner and for the reasons above this also works.

Code:
Name=LDTimer.Add()
LDTimer.Interval(Name,5000)
LDTimer.Tick=OnTimerTick

TextWindow.WriteLine("Start")

Sub OnTimerTick
  TextWindow.WriteLine("Here")
EndSub
[-] The following 1 user Likes litdev's post:
  • jrmrhrb00
Reply


Messages In This Thread
Can't get LDTimers to work - by jrmrhrb00 - 12-25-2023, 08:44 PM
RE: Can't get LDTimers to work - by jrmrhrb00 - 12-26-2023, 12:17 AM
RE: Can't get LDTimers to work - by WhTurner - 12-26-2023, 11:20 AM
RE: Can't get LDTimers to work - by litdev - 12-26-2023, 11:53 AM
RE: Can't get LDTimers to work - by jrmrhrb00 - 12-26-2023, 03:41 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)