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: 
JSM_IT_DEV
Visitor

Pass variable to Task

I have set up the following Task:

<?xml version="1.0" encoding="utf-8" ?>

<!--********** Copyright 2015 Roku Corp. All Rights Reserved. **********-->

<component name="launchSceneTask" extends="Task" >

<interface>
<field id="scene" type="string" />
<field id="video_key" type="string" />
</interface>

<script type="text/brightscript" >
<![CDATA[

sub init()
m.top.functionName = "showSGScene"
end sub

sub showSGScene()
print "in showSGScene"
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)
scene = screen.CreateScene(m.top.scene)
print "VIDEO KEY:"
print m.top.video_key
screen.show()

while(true)
msg = wait(0, m.port)
msgType = type(msg)

if msgType = "roSGScreenEvent"
if msg.isScreenClosed() then return
end if
end while
end sub

]]>
</script>

</component>


And am calling it like so:

function showWatchSGScreen(video_key as String)
m.sceneTask = CreateObject("roSGNode", "launchSceneTask")
m.sceneTask.setField("scene", "watchScene")
m.sceneTask.setField("video_key", video_key)
m.sceneTask.ObserveField("test_trigger", "testFunction")
m.sceneTask.control = "RUN"
end function


However, I get the following error:

Interface not a member of BrightScript Component (runtime error &hf3) in ...A2pJLT7/pkg:/components/homeScene.xml(97)
097: m.sceneTask.setField("scene", "watchScene")


The examples in the documentation seem to be doing it exactly this way. Is there a bug, or is this user error?
0 Kudos
4 REPLIES 4
TheEndless
Channel Surfer

Re: Pass variable to Task

Where are you calling showWatchSGScreen? You can only create Task nodes in certain contexts (I forget which don't work off the top of my head), so it's probably that m.sceneTask is invalid. You could potentially create the task node during init(), then just set the fields and control to "RUN" in your showWatchSGScreen function.
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)
0 Kudos
JSM_IT_DEV
Visitor

Re: Pass variable to Task

I am calling showWatchSGScreen() from Main() in my main.brs file. I've also tried calling it from a KeyDown event in one of my scenes. Neither work.
0 Kudos
TheEndless
Channel Surfer

Re: Pass variable to Task

Right, if you're calling it from Main, then it's running in the main BrightScript context, which doesn't support Task nodes. You should create and configure the Task node in the init() method of your scene, then you should be able to trigger it by setting the control to "RUN" at any point later in execution.
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)
0 Kudos
JSM_IT_DEV
Visitor

Re: Pass variable to Task

You, my friend, are a life-saver. Thank you so much!

Here's the amended code:

In the init() method of my xml component:

m.sceneTask = CreateObject("roSGNode", "launchSceneTask")


In the showWatchSGScreen(video_key as String) method, called from a KeyPress event:

  m.sceneTask.setField("scene", "watchScene")
m.sceneTask.setField("video_key", video_key)
m.sceneTask.control = "RUN"


You've saved my life Smiley LOL