jedashford
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2016
01:27 PM
Can I return a Message from roSGScreen?
How would I send data back from my roSGScreen to my standard brightscript code? Specifically to fire the port listener in the while loop.
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)
scene = screen.CreateScene("onboarding_a")
screen.show()
while(true)
msg = wait(0, m.port)
msgType = type(msg)
if msgType = "roSGScreenEvent" '<----- How can I return something specific back here?
if msg.isScreenClosed() then return 50
end if
end while
5 REPLIES 5
jedashford
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2016
08:42 AM
Re: Can I return a Message from roSGScreen?
Any ideas here? I need to communicate between a scene graph component and a non scene graph component.
- getGlobalNode() isn't an option as it requires all of our customers to upgrade their Roku to 7.1 which isn't even available to all right now.
- Apparently I cant create a reRegistrySection from within Scene Graph so I can't use the registry as a global variable system.
- My last option is to return something back to my brightscript while loop listed in the original post. An insight here can get me back on track.
- getGlobalNode() isn't an option as it requires all of our customers to upgrade their Roku to 7.1 which isn't even available to all right now.
- Apparently I cant create a reRegistrySection from within Scene Graph so I can't use the registry as a global variable system.
- My last option is to return something back to my brightscript while loop listed in the original post. An insight here can get me back on track.

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2016
09:29 AM
Re: Can I return a Message from roSGScreen?
You have a few different options in 7.0.
- You can write to the registry, but it has to be done in a Task node.
- You can write data to a file in tmp:/, which also requires the use of a Task node.
- Depending on the data you want to share, probably most appropriately, you can add a custom interface field on your scene. If you need to respond to changes to the data, you can observe that field using the MessagePort variant of observeField, then listen for roSGNodeEvents in your main BrightScript event loop.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
jedashford
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2016
11:08 AM
Re: Can I return a Message from roSGScreen?
Thanks @TheEndless, this is what I was looking for. I have everything now in place, but theres one small problem. How do I get the port from within scene graph? Specifically :
m.top.ObserveField("buttonChoice", m.top.getMessagePort())
This doesn't work, but I can't find any documentation on any interface to grab the message port. Any ideas?
m.top.ObserveField("buttonChoice", m.top.getMessagePort())
This doesn't work, but I can't find any documentation on any interface to grab the message port. Any ideas?

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2016
11:56 AM
Re: Can I return a Message from roSGScreen?
"jedashford" wrote:
Thanks @TheEndless, this is what I was looking for. I have everything now in place, but theres one small problem. How do I get the port from within scene graph? Specifically :
m.top.ObserveField("buttonChoice", m.top.getMessagePort())
This doesn't work, but I can't find any documentation on any interface to grab the message port. Any ideas?
The message port is the same one you create and assign to roSGScreen on channel launch.
You wouldn't call observeField from within your scene/component. You'd call it from the main BrightScript code where you want to receive the data.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
jedashford
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2016
03:23 PM
Re: Can I return a Message from roSGScreen?
Thanks @TheEndless. I realized the same right after I re-read your previous message. This is the best way IMO to implement a hybrid channel.
For those others that find this:
In the main brightscript code that creates the scene:
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)
scene = screen.CreateScene("onboarding_a")
screen.show()
scene.ObserveField("buttonChoice",m.port)
while(true)
msg = wait(0, m.port)
msgType = type(msg)
PRINT "TYPE: "; msgType
PRINT "msg: "; msg
if msgType = "roSGNodeEvent" then
if (msg.GetField() = "buttonChoice" AND msg.GetData() = "create") then
'do something here
else if (msg.GetField() = "buttonChoice" AND msg.GetData() = "link") then
'do something here
end if
else if msgType = "roSGScreenEvent" then
if msg.isScreenClosed() then
return 50
end if
end if
end while
Within the scene create the interface:
<interface>
<field id="buttonChoice" type="string" value="none"/>
</interface>
Now whenever buttonChoice is changed within the scene it will send a message through the port back to your main loop listening to m.port.
simple change:
m.top.buttonChoice = "link"
For those others that find this:
In the main brightscript code that creates the scene:
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)
scene = screen.CreateScene("onboarding_a")
screen.show()
scene.ObserveField("buttonChoice",m.port)
while(true)
msg = wait(0, m.port)
msgType = type(msg)
PRINT "TYPE: "; msgType
PRINT "msg: "; msg
if msgType = "roSGNodeEvent" then
if (msg.GetField() = "buttonChoice" AND msg.GetData() = "create") then
'do something here
else if (msg.GetField() = "buttonChoice" AND msg.GetData() = "link") then
'do something here
end if
else if msgType = "roSGScreenEvent" then
if msg.isScreenClosed() then
return 50
end if
end if
end while
Within the scene create the interface:
<interface>
<field id="buttonChoice" type="string" value="none"/>
</interface>
Now whenever buttonChoice is changed within the scene it will send a message through the port back to your main loop listening to m.port.
simple change:
m.top.buttonChoice = "link"