johnmarsden
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2017
01:44 PM
Accessing global functions in SceneGraph components?
Hey there,
How do you access global functions from within Scene Graph *.brs files? I have a utility class that has things like toString(), getScreenHeight(), etc that I want to access.
There's a component being included called Menu.xml, which reaches out to a Menu.brs class that has a "init()" function. I've tried things like
But none of it works. What's the best approach for accessing global utility functions from within components?
Thanks!
How do you access global functions from within Scene Graph *.brs files? I have a utility class that has things like toString(), getScreenHeight(), etc that I want to access.
' source/utility/general.brs
function toString(var)
return ...
end function
There's a component being included called Menu.xml, which reaches out to a Menu.brs class that has a "init()" function. I've tried things like
m.global.toString("test")
m.top.toString("test")
m.toString("test")
toString("test")
But none of it works. What's the best approach for accessing global utility functions from within components?
Thanks!
11 REPLIES 11
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2017
07:06 PM
Re: Accessing global functions in SceneGraph components?
Copying the function you need into the component/duplicating it works.
tmat1075
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2017
08:12 AM
Re: Accessing global functions in SceneGraph components?
What I've been doing is add an extra "script" tag to each of the xml files.
<?rokuml version="1.0" encoding="utf-8" ?>
<!-- a Task handling the playback loop of both content abd ad -->
<component name="PlayerTask" extends="Task">
<script type="text/brightscript" uri="pkg:/components/PlayerTask.brs" />
<script type="text/brightscript" uri="pkg:/components/Helpers/VideoHelpers.brs"/>
<interface>
<field id="video" type="node" />
</interface>
</component>
NB_
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2017
10:18 AM
Re: Accessing global functions in SceneGraph components?
Currently you cannot share global/utility functions between different components. There have been multiple requests to make that possible, keep asking and hopefully that will happen.
The workaround in use is duplicating code - whether literally or including via <script .../>, which leads to the same code being compiled/baked separately in each component. Please beware that using this too liberally may notably slow your components or launch times.
The workaround in use is duplicating code - whether literally or including via <script .../>, which leads to the same code being compiled/baked separately in each component. Please beware that using this too liberally may notably slow your components or launch times.
johnmarsden
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2017
02:55 PM
Re: Accessing global functions in SceneGraph components?
What's the cost of passing references from an instantiated object to each component? I have an instantiated class called "String" that i want to pass to components by reference. I'm assuming this wont be too damaging or resource consuming correct? Will BrightScript duplicate referenced objects if passed to a component even though they aren't re instantiated?
NB_
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2017
05:57 PM
Re: Accessing global functions in SceneGraph components?
"johnmarsden" wrote:
What's the cost of passing references from an instantiated object to each component? I have an instantiated class called "String" that i want to pass to components by reference. I'm assuming this wont be too damaging or resource consuming correct? Will BrightScript duplicate referenced objects if passed to a component even though they aren't re instantiated?
Not sure i understand the question. By "instantiated class" do you mean a roAssociativeArray object with values and functions in it? If so, please note that RSG currently does not support functions inside component fields. See a list of what is supported here https://sdkdocs.roku.com/display/sdkdoc ... Attributes
The unsupported elements - in this case functions - would just be silently stripped away.
johnmarsden
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017
04:03 PM
Re: Accessing global functions in SceneGraph components?
Ah yes, I'm seeing that now. Stripped away after passing them in 😞 That's unfortunate.
Tyler_Smith
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2017
10:06 PM
Re: Accessing global functions in SceneGraph components?
Something we've been doing is storing a Utility component in the global scope and exposing our utilities via functional fields.
You can see how to add functional fields to a component here:
https://sdkdocs.roku.com/display/sdkdoc ... onalFields
Sample implementation/call:
You can see how to add functional fields to a component here:
https://sdkdocs.roku.com/display/sdkdoc ... onalFields
Sample implementation/call:
m.global.addFields({
Utilities: CreateObject("UtilityComponent")
})
m.global.Utilities.callFunc("myFunction", {})
Tyler Smith

georgejecook
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2018
03:46 PM
Re: Accessing global functions in SceneGraph components?
@tylersmith - you sir, rock!
I had missed functional fields, and their wonderful promise until I saw this - THANKS.
I had missed functional fields, and their wonderful promise until I saw this - THANKS.
George Cook
https://georgejecook.github.io/
https://linkedin.com/in/georgejecook/
Roku developers slack group (https://join.slack.com/t/rokudevelopers/shared_invite/zt-4vw7rg6v-NH46oY7hTktpRIBM_zGvwA) : georgejecook
Contact me on roku developer slack group, or via pm to discuss consultancy/work opportunities/rooibos unit testing framework
https://georgejecook.github.io/
https://linkedin.com/in/georgejecook/
Roku developers slack group (https://join.slack.com/t/rokudevelopers/shared_invite/zt-4vw7rg6v-NH46oY7hTktpRIBM_zGvwA) : georgejecook
Contact me on roku developer slack group, or via pm to discuss consultancy/work opportunities/rooibos unit testing framework
Tyler_Smith
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2018
06:08 PM
Re: Accessing global functions in SceneGraph components?
You're welcome 🙂
Tyler Smith