slingxshot
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2017
12:43 PM
Passing Data from main.brs
Does anyone know how to pass data from main.brs to the scene components?
I tried m.global and got an error.
Thanks!
I tried m.global and got an error.
Thanks!
6 REPLIES 6
squirreltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2017
01:28 PM
Re: Passing Data from main.brs
m.global = screen.getGlobalNode()
m.global.AddField("token", "string", false)
m.global.token= "thisstring"
Put this in Main.brs and it should be available everywhere.
Kinetics Screensavers
slingxshot
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2017
02:26 PM
Re: Passing Data from main.brs
awesome. I didn't realize that you need to associate it with the screen.
ib_beat
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017
09:16 AM
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
And I got this error here in the console:
Any ideas?
This is what I put in the main.brs
sub RunUserInterface()
user_id = regread("id","user_data")
user_sub = regread("sub","user_data")
?user_id
?user_sub
m.global = screen.getGlobalNode()
m.global.AddField("userId", "string", false)
m.global.AddField("subscription", "string", false)
m.global.userId = user_id
m.global.subscription = user_sub
? "User sub global = " + m.global.userId
if user_id <> invalid then
ShowContens(invalid)
else
ShowLogin(invalid)
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()
005:
006: user_id = regread("id","user_data")
007: user_sub = regread("sub","user_data")
008: ?user_id
009: ?user_sub
010:
011:* m.global = screen.getGlobalNode()
012: m.global.AddField("userId", "string", false)
013: m.global.AddField("subscription", "string", false)
014: m.global.userId = user_id
015: m.global.subscription = user_sub
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in pkg:/source/main.brs(11)
011: m.global = screen.getGlobalNode()
Backtrace:
#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:"test@example.com"
user_sub roString (2.1 was String) refcnt=1 val:"False"
screen <uninitialized>
Brightscript Debugger>
Any ideas?
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017
12:24 PM
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.
joetesta
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017
04:13 PM
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
choose "type" that makes sense. Then in main,
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...?
In component
<interface>
<field id="YourNewField" type="assocarray" onChange="myFunctionThatDoesSomething"/>
</interface>
choose "type" that makes sense. Then in main,
comp = m.top.findnode("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 m.top.YourNewField
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...?
aspiring
ib_beat
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2017
05:36 AM
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.
Thanks!!
It now works properly.
Thanks!!