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: 
belltown
Roku Guru

Re: Is there a complete guide on roSGNode?

"RokuMarkn" wrote:
"scaper12123" wrote:
Admittedly the possibilities of time-zone differences have made me lag a bit but that's about the worst of it.


When you asked about using AsSeconds in another thread, I said "assuming both roDateTimes are in GMT, this will work". I emphasize again that you must operate in GMT. NEVER use local time for any time calculations -- it will fail, due to the fact that local time is neither monotonic nor unambiguous (for example, the local time 1:30am occurs twice on the same day when Daylight Saving Time ends). The only thing local time should be used for is to display times to the user.

--Mark

Good point. I've edited my example code above to display the time using the user's local time zone. As Mark said, make sure the time calculations are done using GMT time. If your server returns time in a different time zone, then convert from that time zone to GMT before doing any further calculations on the time.
0 Kudos
scaper12123
Visitor

Re: Is there a complete guide on roSGNode?

"belltown" wrote:
Good point. I've edited my example code above to display the time using the user's local time zone. As Mark said, make sure the time calculations are done using GMT time. If your server returns time in a different time zone, then convert from that time zone to GMT before doing any further calculations on the time.


Hi there! This is me, replying a few days later. I took a good hard look at your code and I was able to get a description of streaming time in the description categories of the roListScreen nodes, so that was exciting! I am still struggling with the countdown timer I'm trying to make, however. I did realize what my problem was: I was misunderstanding the use of the Timer node in roSGNode. I am instead trying to make a Label node to display time in an hh:mm:ss format. My strategy is to update the label every second and change the time. If there is a more efficient way of making a visual countdown timer, please let me know.

In the meanwhile, I'm having trouble understanding how to add fields to the roSGNode when I create them, and how to make them the focused object on the screen. The following is my code with my best guess as to how it's done. I would appreciate it if somebody could help me figure out what I'm doing wrong (when I attempt to create a node, I get an error in the console saying "Failed to create roSGNode with type Label):
'live is an associative array with the following values:
' start = time which the stream should start
' end = predicted end time for the livestream
' current = a roDateTime object to represent the system time (in UTC)

'stream is just an associative array with one member: stream
' stream contains the fields needed to create the livestream,
' when used as a field in VideoPlayer()

sub CountdownDisplay(live as object, stream as object)
'create initial objects and show scene, so node can be created later
screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.Show()

'obtain the time left for initial display of countdown timer
secondsLeft = live.start.AsSeconds() - live.current.AsSeconds()

'here I need to do something to create a visual countdown display
countdown = CreateObject("roSGNode", "Label") 'because this fails to execute, the next three lines crash the program
countdown.vertAlign = center
countdown.horizAligin = center
countdown.text = CountdownTime(secondsLeft) 'CountdownTime() returns a string with format hh:mm:ss

while true
msg = wait(1000, port) 'check for updates every second
if msg = Invalid
live.current.Mark() 'mark the time to ensure it's up to date

secondsLeft = live.start.AsSeconds() - live.current.AsSeconds() 'update secondsLeft
if secondsLeft > 0
'here I need to modify the countdown to display an updated time
countdown.text = CountdownTime(secondsLeft)
else
'assume wait time is over, get rid of the countdown screen, and go to the livestream
screen.Close()
VideoPlayer(stream)
end if
else if type(msg) = "roSGScreenEvent"
if msg.IsScreenClosed()
exit while
end if
end if
end while

return
end sub
I AM THE ARCHMAGE... who is also rather new to Brightscript so forgive me for seeming inept at times.
0 Kudos