Forum Discussion

scaper12123's avatar
10 years ago

Help with using roSGNode?

EDIT: My problem has changed slightly, but it still involves roSGNodes so I'll just append this post with the issue I'm having. If anybody can help me I would very much appreciate it! 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 following 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'm trying to use roSGNode to make a label in order to provide a user with some information, but my attempts to learn how to use roSGNode have been turning up stagnate. The documentation only tells me how to form the node, and I don't know how to get all the data I need into the node object or how to properly display it. Below is my current attempt which failed.

	screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)

'scene = screen.CreateScene("timer")
screen.show()

label = CreateObject("roSGNode", "Label")
label.horizAlign = "center"
label.vertAlign = "center"
label.translation="[0,500]"
label.width="1280"
label.text = "there is no stream right now."

label.setFocus()


Apparently you're not supposed to use the node.field subtext even though the documentation suggests doing so. Could somebody help me straighten out what I'm supposed to do in this scenario?

EDIT: I tried investigating the documentation and used this code to see what would happen:
	screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)

'scene = screen.CreateScene("timer")
screen.show()

label = CreateObject("roSGNode", "Label")
aa={horizAlign: "center"
vertAlign: "center"
translation: "[0,500]"
width: "1280"
text: "there is no stream right now."
}
label.AddFields(aa)

label.setFocus()

When I ran the program, it told me that it failed to create an roSGNode with type Label, even though it worked the first time. Am I missing something?

11 Replies

  • "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