I understand that to pass information from a scene graph node, I can set observeField with the field name and a message port to listen on. What I don't understand is how to assign the same message port in observeField that I am listening on in the roSGScreen's event loop. If I create the message port in the main thread so I can set it to the roSGScreen, how can I send it into the scene graph's thread so it can be set on observeField? Below is the basic code I'm working with:
Main:
'create the screen graph component and set it up with a message port
screen = CreateObject("roSGScreen")
sceneGraphPort = CreateObject("roMessagePort")
screen.SetMessagePort(sceneGraphPort)
'set the xml component by name, that will be displayed on the screen
screen.createScene("appScene")
'display the scene on the screen
screen.show()
'listen for any events associated with the scene
while true
msg = wait(0, sceneGraphPort)
if type(msg) = "roSGScreenEvent"
if msg.isScreenClosed()
return
end if
else if type(msg) = "roSGNodeEvent"
print "node "; msg.getNode()
print "field name "; msg.getField()
print "data "; msg.data()
end if
end while
Scene Graph:
<?xml version="1.0" encoding="utf-8" ?>
<component name="appScene" extends="Scene" >
<script type="text/brightscript" >
<![CDATA[
sub init()
print "-----------STARTING GRAPH SCENE-----------"
m.leftRectangle = m.top.findNode("leftRectangle")
m.leftRectangle.observeField("color", sceneGraphPort)
m.top.setFocus(true)
end sub
function onKeyEvent(key as String, press as Boolean) as Boolean
handled = false
if press then
if (key = "OK")
m.leftRectangle.color = "0x0000FFFF"
handled = true
end if
end if
return handled
end function
]]>
</script>
<children>
<Rectangle
id="leftRectangle"
width="300"
height="300"
color="0xFF0000FF"
translation="[100,100]" />
</children>
</component>
The end result is once the scene graph is loaded, if the user presses "ok", the square should turn from green to blue.
The issue is, unsurprisingly, sceneGraphPort is uninitialized in the scene graph thread. Any advice how to set the port in the scene graph thread, that I'm listening to in the main thread? Or am I thinking about this all wrong? Did I miss something in the documentation that explains how to do this?