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

Scene Not Returning To brs

Seem to hit a brick wall with each new turn. Attempting to rewrite app to scene graph. Something so simple is proving to be difficult. When app initially starts it checks for userinfo in the registry. If it exist, the app continues, if not it enters into a scene where the user inputs info like zipcode and state abbreviation. Once this is complete, the user selects continue and control is suppose to return to the brs file to write the info to the registry. Not sure what I am doing wrong, the scene does what is required but the brs doesn't pick up and continue. The scene screen closes and nothing. When I press the "HOME" key I can see that the brs continues to next step but at that point the app is exited. Posting each section below.

main.brs
Sub RunUserInterface()
showChannelSGScreen()
End Sub

sub showChannelSGScreen()
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)
scene = screen.CreateScene("BackGroundScreen")
screen.show()
userdata()
while(true)
  msg = wait(0, m.port)
  msgType = type(msg)
  if msgType = "roSGScreenEvent"
    if msg.isScreenClosed()
     Exit While
     else
         END IF
  end if
end while
end sub

Function userdata()
userinfo=GetAuthData()
end function

Function GetAuthData() As Dynamic
?"IN GetAuthData"
     sec = CreateObject("roRegistrySection", "Authentication")
if sec.Exists("UserRegistrationToken")
          ?"USER DATA NOT EMPTY"
else
?"USER DATA  EMPTY"
     screen = CreateObject("roSGScreen")
     screen.setMessagePort(m.port)
     scene = screen.CreateScene("ZIPCODE")
     screen.show()
while(true)
        msg = wait(0, m.port)
        msgType = type(msg)
        ?msgType
        if msgType = "roSGScreenEvent"
          if msg.isScreenClosed()
          ?"RETURN"       'NEVER GETS HERE UNTIL HOME BUTTON IS PRESSESD
                 EXIT WHILE
         end if
      end if
      end while
end if
End Function

ZIPCODE.XML-  onKeyEvent only

  function onKeyEvent(key as String, press as Boolean) as Boolean   
button_val = m.top.dialog.buttonSelected
        if not press then
            if key = "OK"
                m.count=m.count + 1
                      if(button_val = 0) and (m.count=6)
                            m.zip=m.pad.pin
                            m.top.dialog.close = true
                            setstate()
                      else if (button_val=0) and (m.count=9)
                            m.statec= m.key.text
                            zipstate=m.zip + m.statec
                            content = CreateObject("roSGNode", "ContentNode")
                            dataItem = content.CreateChild("ContentNode")
                            dataItem.addfields({"zipstate": m.zip + m.statec })
                            m.top.content=content
                            m.top.dialog.close = true
                            return true
                      else if (button_val = 1)
                      Print "CANCEL ZIP ENTRY"
                      m.top.dialog.close = true
                      return true
                      end if
                    end if
                end if
            return FALSE
            end function
0 Kudos
2 REPLIES 2
belltown
Roku Guru

Re: Scene Not Returning To brs

Don't try to "return to the brs file" to write to the registry. Create a Task to do that, which can be used from your Scene, e.g:

TaskRegistry.xml:

<?xml version="1.0" encoding="UTF-8"?>
<component name="TaskRegistry" extends="Task">
 <script type="text/brightscript" uri="pkg:/components/TaskRegistry.brs" />
 <interface>
   <field id="write" type="assocarray" />
 </interface>
</component>


TaskRegistry.brs:

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

function taskRun() as void
   registrySection = CreateObject("roRegistrySection", "Authentication")
   if Type(m.top.write) <> "roAssociativeArray"
       print "TaskRegistry.brs. Invalid m.top.write"
   else
       value = FormatJson(m.top.write)
       if value <> ""
           if not registrySection.Write("Data", value)
               print "TaskRegistry.brs. Error writing to registry"
           else if not registrySection.Flush()
               print "TaskRegistry.brs. Error flushing registry"
           end if
       else
           print "TaskRegistry.brs. FormatJson failed"
       end if
   end if
end function


In your Scene XML file:

<children>
...
   <TaskRegistry id="taskRegistry" />
...
</children>


And to write to the registry from your Scene brs code:


   ...
   m.taskRegistryNode = m.top.findNode("taskRegistry")
   ...
   data =    {
             ...
             UserRegistrationToken: token
             ...
             }
   m.taskRegistryNode.write = data
   m.taskRegistryNode.control = "RUN"

Note, in this example I'm storing a field in the registry with a key of "Data" that can contain a bunch of different items put into an associative array then converted to a string using FormatJson. You can store your registry data however you want, but the general principle is the same.
0 Kudos
btpoole
Channel Surfer

Re: Scene Not Returning To brs

Thanks belltown. Figured I'd end up using a task to do it was just hoping to use what I had from old app. I guess I can still use alot of the brs from old app but incorporate it like you have shown me using a task and including the script.
 Thanks again.
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.