Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
breger
Visitor

roTimer vs roTimeSpan

So Roku has roTimeSpan and BrightSign has roTimer. I'm looking for something to function as an asynchronous timer event, which roTimer would work. But roTimeSpan is just a stopwatch. Ideally I would like to provide an roMessagePort object to the timer so it could trigger TimerEvents. Anyone?
0 Kudos
6 REPLIES 6
RokuMarkn
Visitor

Re: roTimer vs roTimeSpan

You can just use a short timeout on your wait call and periodically check whether it is time to perform your action.

--Mark
0 Kudos
RokuJoel
Binge Watcher

Re: roTimer vs roTimeSpan

or you can have an array or roTimeSpan objects and an array of execution times, and an array of functions to execute, something like this:

timerArray=[createobject("roTimeSpan"),createobject("roTimeSpan"),createobject("roTimeSpan"),createobject("roTimeSpan")]
timeouts=[15,30,50,100]
exec[func1,func2,func3,func4]

while true
for i=0 to timearray.count() -1
if timeouts[i] >= timerArrray[i].totalmilliseconds() then
exec[i]()
timerArray[i].mark()
end for
end while


- Joel
0 Kudos
breger
Visitor

Re: roTimer vs roTimeSpan

"RokuJoel" wrote:
or you can have an array or roTimeSpan objects and an array of execution times, and an array of functions to execute, something like this:

...

- Joel


Joel, this was what I thought I would have to do. I was going to have an array of roAssocArrays. Two members of the AssocArray would be the roTimeSpan object and the timeout time. When the timeout time was reached, another object in the array, lets say an imagecanvas, would be there so the programmer knew what the timer was associated with.

"RokuMarkn" wrote:
You can just use a short timeout on your wait call and periodically check whether it is time to perform your action.

--Mark


Mark, your suggest is much like Joel's right? Except he doesn't have a wait. I figure in my eventloop i will need a msg=wait(0,port) at the top, then check my timers, and then keep checking the msg if anything was received.
0 Kudos
RokuMarkn
Visitor

Re: roTimer vs roTimeSpan

I'm assuming your app needs to do something other than trigger the timers. It has a screen or something that it needs to manage at the same time, right? So you would just modify your existing event loop to add a timeout to wait (eg. wait(timeout, port)) and then after the wait check your timers as you said. Note that you must use a nonzero timeout or the wait will just wait until you get a keypress or other real event, which may happen after your timers need to fire. Also note that you really only need one roTimespan, which acts like a clock. Each timer needs to know what time it expires, but it doesn't need a separate roTimespan to do that, just an integer (milliseconds on the clock).

--Mark
0 Kudos
breger
Visitor

Re: roTimer vs roTimeSpan

"RokuMarkn" wrote:
I'm assuming your app needs to do something other than trigger the timers. It has a screen or something that it needs to manage at the same time, right? So you would just modify your existing event loop to add a timeout to wait (eg. wait(timeout, port)) and then after the wait check your timers as you said. Note that you must use a nonzero timeout or the wait will just wait until you get a keypress or other real event, which may happen after your timers need to fire. Also note that you really only need one roTimespan, which acts like a clock. Each timer needs to know what time it expires, but it doesn't need a separate roTimespan to do that, just an integer (milliseconds on the clock).

--Mark


So I should call timer.mark() when i create the timer object. Then if I have something that has a 4 second 'delay', I should read the timeinseconds(), add 4, and save that number and use that to compare?
0 Kudos
RokuMarkn
Visitor

Re: roTimer vs roTimeSpan

"breger" wrote:

So I should call timer.mark() when i create the timer object. Then if I have something that has a 4 second 'delay', I should read the timeinseconds(), add 4, and save that number and use that to compare?


Basically correct. An roTimespan is automatically marked when it is created, so it's not necessary to call Mark(), but it doesn't hurt. I like to use milliseconds rather than seconds, especially when the durations are short, as it reduces the granularity of the timer error. Using seconds, your trigger could be up to 1 second late.

--Mark
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.