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: 
btpoole
Channel Surfer

Help on Dialog Box

I know this should be fairly simple but missing it. Trying to create a dialog that can be used from multiple locations in app by setting the title and message then calling the dialog. Not sure what I maybe missing. If gets in the dialogTask then get the error
=================================================================
Warnings occurred while spawning thread for Task component dialogTaskRegistry
spawning thread aborted because: channel exit or timeout waiting for render thread
=================================================================
Any help appreciated.

initial.brs

m.callDialog=CreateObject("RoSGNode", "dialogTask")
    m.callDialog.titles="TEST"
    m.callDialog.messages="TEST TEST"
    m.calldialog.control="RUN"


dialogTask.xml
<?xml version="1.0" encoding="UTF-8"?>
<component name="dialogTask" extends="Task">
  <interface>
    <field id="titles" type="string" />
    <field id="messages" type="string" />
  </interface>
  <script type="text/brightscript" uri="pkg:/components/dialogs/dialog.brs" />
<script type = "text/brightscript" >
  <![CDATA[
  sub init()
  ?"in dialogTask"
  m.top.functionName="dialog"
  end sub
    ]]>
  </script>
</component>


dialogScene.xml
<?xml version = "1.0" encoding = "utf-8" ?>
<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->
<component name = "dialogInfoScene" extends = "Scene" >
  <script type="text/brightscript" uri="pkg:/components/dialogs/dialog.brs" />
  <script type = "text/brightscript" />
  <children>
    <Label
      id = "instructLabel"
      text = "" />
      <Poster
          id="Background"
          width="1280"
          height="720"
          />
  </children>
</component>

dialogs.brs
function Dialog()
?"in Dialogs"
titlevalue=m.top.titles
messagevalue=m.top.messages
m.background  = m.top.findNode("Background")
example = m.top.findNode("instructLabel")
examplerect = example.boundingRect()
centerx = (1280 - examplerect.width) / 2
centery = (720 - examplerect.height) / 2
example.translation = [ centerx, centery ]
m.top.setFocus(true)
di = CreateObject ("roDeviceInfo")
serial=di.GetDeviceUniqueId()
dialog = createObject("roSGNode", "Dialog")
dialog.title = titlevalue
dialog.optionsDialog = true
dialog.message =messagevalue
m.top.dialog = dialog
end function
0 Kudos
8 REPLIES 8
btpoole
Channel Surfer

Re: Help on Dialog Box

So I guess it is not possible to create a reusable dialog that can have title and message set out side of the scene and called from anywhere in the app thru a task?
0 Kudos
NB_
Roku Guru

Re: Help on Dialog Box

"btpoole" wrote:

=================================================================
Warnings occurred while spawning thread for Task component dialogTaskRegistry
spawning thread aborted because: channel exit or timeout waiting for render thread
=================================================================

Methinks your problem is elsewhere.
0 Kudos
btpoole
Channel Surfer

Re: Help on Dialog Box

"RokuNB" wrote:
"btpoole" wrote:

=================================================================
Warnings occurred while spawning thread for Task component dialogTaskRegistry
spawning thread aborted because: channel exit or timeout waiting for render thread
=================================================================

Methinks your problem is elsewhere.

Can you tell me if it is possible to set the title and message of a dialog box thru a task, then call the dialog? Just looking to have one dialog that can be used thru out the app with dynamic title and message.
0 Kudos
NB_
Roku Guru

Re: Help on Dialog Box

"btpoole" wrote:
Can you tell me if it is possible to set the title and message of a dialog box thru a task, then call the dialog? Just looking to have one dialog that can be used thru out the app with dynamic title and message.

My apologies, since i dont have time to take your code and make it work - but I know no reason why this would be impossible. I also don't know a reason of why you should be using a Task for that and not do it directly. The problem you saw seems to be because your app exits before that or there is some other timeout happening.
0 Kudos
btpoole
Channel Surfer

Re: Help on Dialog Box

"RokuNB" wrote:
"btpoole" wrote:
Can you tell me if it is possible to set the title and message of a dialog box thru a task, then call the dialog? Just looking to have one dialog that can be used thru out the app with dynamic title and message.

My apologies, since i dont have time to take your code and make it work - but I know no reason why this would be impossible. I also don't know a reason of why you should be using a Task for that and not do it directly. The problem you saw seems to be because your app exits before that or there is some other timeout happening.

Ok forget the task. Just say I have function as below
function generalScene()
?"in generalScene"
screen = CreateObject("roSGScreen")
screen.setMessagePort(m.port)
scene = screen.CreateScene("generalInfoScene")
screen.show()
    while (true)
      msg = wait(0, m.port)
        msgType = type(msg)
       if msgType = "roSGScreenEvent"
          if msg.isScreenClosed()
            EXIT WHILE
          end if
        end if
        end while
end function

Creates the scene.  How would I set the title in the scene dynamically so the same code could be used to display different a different title and message? I know how to set a field in a task but not sure about the scene.
<?xml version = "1.0" encoding = "utf-8" ?>
<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->
<component name = "generalInfoScene" extends = "Scene" >
  <interface>
 
    <field id="title" type = "string" />

    </interface>
  <script type="text/brightscript" uri="pkg:/source/main.brs" />
  <script type = "text/brightscript" >
    <![CDATA[
    sub init()
    generalDialog()
    end sub

    sub generalDialog()
        m.background  = m.top.findNode("Background")
      example = m.top.findNode("instructLabel")
      examplerect = example.boundingRect()
      centerx = (1280 - examplerect.width) / 2
      centery = (720 - examplerect.height) / 2
      example.translation = [ centerx, centery ]
      m.top.setFocus(true)
   
      dialog = createObject("roSGNode", "Dialog")
      dialog.title = m.top.title
      dialog.optionsDialog = true
      dialog.message = "TEST MESSAGE"
      m.top.dialog = dialog
      end sub
    ]]>

  </script>
  <children>


    <Label
      id = "instructLabel"
      text = "" />

      <Poster
          id="Background"
          width="1280"
          height="720"
          />

  </children>


</component>

0 Kudos
NB_
Roku Guru

Re: Help on Dialog Box

"btpoole" wrote:
How would I set the title in the scene dynamically so the same code could be used to display different a different title and message? I know how to set a field in a task but not sure about the scene.

Just the same, something like:

sub generalDialog(title, message)
dialog = createObject("roSGNode", "Dialog")
dialog.title = title
dialog.message = messsage
dialog.optionsDialog = true
m.top.dialog = dialog
end sub
0 Kudos
btpoole
Channel Surfer

Re: Help on Dialog Box

"RokuNB" wrote:
"btpoole" wrote:
How would I set the title in the scene dynamically so the same code could be used to display different a different title and message? I know how to set a field in a task but not sure about the scene.

Just the same, something like:

sub generalDialog(title, message)
   dialog = createObject("roSGNode", "Dialog")
   dialog.title = title
   dialog.message = messsage
   dialog.optionsDialog = true
   m.top.dialog = dialog
end sub


Thank you RokuNB. 
0 Kudos
btpoole
Channel Surfer

Re: Help on Dialog Box

"RokuNB" wrote:
"btpoole" wrote:
How would I set the title in the scene dynamically so the same code could be used to display different a different title and message? I know how to set a field in a task but not sure about the scene.

Just the same, something like:

sub generalDialog(title, message)
   dialog = createObject("roSGNode", "Dialog")
   dialog.title = title
   dialog.message = messsage
   dialog.optionsDialog = true
   m.top.dialog = dialog
end sub


I understand how calling the function and passing the info to the sub or function will work, but in this case it's not possible. In the main.brs a busyspinner is initiated, from there several functions are executed and depending on results a dialog box may appear.  Each dialog box is being created from a function that creates a scene for the individual dialog. I am attempting to eliminate the multiple functions that create the scenes and have one function that will create one scene. In the process of doing this a dialog title and dialog message will be set. The scene that creates the dialog is not located in the source folder.
main.brs
Sub RunUserInterface()
Print "RUNUSERINTERFACE"
screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)
scene = screen.CreateScene("BusySpinnerExample")
screen.show()
presetup()
end sub

sub presetup()
response=usercheck()
if response= 1
checkStatus()
else
do something else
end if
end sub


function checkstatus()
if m.global.info=0
dialogtitle= "TITLE OF 0"
dialogmessage= "0 message here"
else
dialogtitle= "TITLE NOT 0"
dialogmessage= "NOT 0 message here"
end if

m.utility=createobject("rosgnode", "utilityScene")
m.utility.addfields({"title": dialogtitle, "message": dialogmessage})

setutility()    'located in source folder

end function


setutility.brs
function setutility()
screen = CreateObject("roSGScreen")
screen.setMessagePort(m.port)
scene = screen.CreateScene("utilityScene")
screen.show()
  while
      msg = wait(0, m.port)
        msgType = type(msg)
       if msgType = "roSGScreenEvent"
          if msg.isScreenClosed()
            EXIT WHILE
          end if
        end if
        end while

end function

utilityScene.xml   this located in the components folder
<component name="utilityScene" extends="Scene" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">

  <interface>
    <field id= "title" type = "string"/>
    <field id=  "message" type= "string" />
    </interface>
  <script type = "text/brightscript" >

    <![CDATA[

    sub init()
    dialogNON()
    end sub


    sub dialogNON()
    ?"utilityScene"
      m.background  = m.top.findNode("Background")
      example = m.top.findNode("instructLabel")
      examplerect = example.boundingRect()
      centerx = (1280 - examplerect.width) / 2
      centery = (720 - examplerect.height) / 2
      example.translation = [ centerx, centery ]
      m.top.setFocus(true)
     dialog = createObject("roSGNode", "Dialog")
      dialog.title = m.top.title
      dialog.optionsDialog = true
      dialog.message = m.top.message
      m.top.dialog = dialog
      end sub
    ]]>
  </script>
  <children>
    <Label
      id = "instructLabel"
      text = "" />
      <Poster
          id="Background"
          width="1280"
          height="720"
          />
  </children>
</component>


The code works perfect except the title and message never get set. If I hard code the title and message into the appropriate locations dialog appears as expected. What is missing in setting the fields of the scene?
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.