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
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.
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?
“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.
Hey @tylersmith - don’t spose you’ve got an example of any of your util methods.. just want to be sure I’m structuring things right.. i.e. what is your util class? xml node/task?
I’m trying to architect what I’m doing in a way that suits 7.6+ firmware - most all examples seem architecturally years old - I wish Roku woudl update their docs/apps to reflect their new provisions - God alone knows how many people are observing fields left right center haplessly, or how many people don’t know that you can efficiently copy in .brs files to .xml since 7.5 - I think their own docs state that’s a performance risk; yet the release notes for 7.5 clearly supersede that..
So many ways to scew up making an app..
sorry for rant - if you woulnd’t, pleeasssse, mind just giving me a snippet with even just 1 util function to show how you’re using it. I’d really be in your debt.