Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 7

Passing Data from main.brs

Does anyone know how to pass data from main.brs to the scene components?

I tried and got an error.

0 Kudos
Level 9

Re: Passing Data from main.brs = screen.getGlobalNode()"token", "string", false) "thisstring"

Put this in Main.brs and it should be available everywhere.
Kinetics Screensavers
0 Kudos
Level 7

Re: Passing Data from main.brs

awesome. I didn't realize that you need to associate it with the screen.
0 Kudos
Level 7

Re: Passing Data from main.brs

I stumbled across the same issue, but I couldn't make it work.
This is what I put in the main.brs
sub RunUserInterface() 

    user_id = regread("id","user_data")
    user_sub = regread("sub","user_data")
    ?user_sub = screen.getGlobalNode()"userId", "string", false)"subscription", "string", false) = user_id = user_sub
    ? "User sub global = " +
    if user_id <> invalid then
    end if    
end sub

And I got this error here in the console:
BrightScript Micro Debugger.
Enter any BrightScript statement, debug commands, or HELP.

Current Function:
004:  sub RunUserInterface()
006:      user_id = regread("id","user_data")
007:      user_sub = regread("sub","user_data")
008:      ?user_id
009:      ?user_sub
011:* = screen.getGlobalNode()
012:"userId", "string", false)
013:"subscription", "string", false)
014: = user_id
015: = user_sub
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in pkg:/source/main.brs(11)
011: = screen.getGlobalNode()
#0  Function runuserinterface() As Void
   file/line: pkg:/source/main.brs(11)
Local Variables:
global           Interface:ifGlobal
m                roAssociativeArray refcnt=2 count:0
user_id          roString (2.1 was String) refcnt=1 val:""
user_sub         roString (2.1 was String) refcnt=1 val:"False"
screen           <uninitialized>

Brightscript Debugger>

Any ideas?
0 Kudos
Level 10

Re: Passing Data from main.brs

If "screen" doesn't exist then you can't access it -- create the scene first, then create a screen, and there you go.
0 Kudos
Level 11

Re: Passing Data from main.brs

or instead of using global, add the field to your component's interface and you can pass data to the component into that field. 

In component

<field id="YourNewField" type="assocarray" onChange="myFunctionThatDoesSomething"/>

choose "type" that makes sense.  Then in main,

comp ="componentID")  (or probably you already have a handle to it)
comp.YourNewField = Data of the correct type Passed in to new field and seen by component via

 As I understand this is less "expensive" and if you don't need the data globally, is the best practice.  Although I could be wrong about the expense...?
0 Kudos
Level 7

Re: Passing Data from main.brs

Oh god... I missed that completely. I created the scene first and it solved the issue.
It now works properly.

0 Kudos