Your Digital Media Has Never Looked So Good

 
johnmarsden
Topic Author
Posts: 36
Joined: Wed Nov 18, 2015 1:37 pm

Accessing global functions in SceneGraph components?

Fri May 12, 2017 1:44 pm

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. 
' 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!
 
User avatar
destruk
Posts: 2361
Joined: Sat Dec 18, 2010 4:58 pm

Re: Accessing global functions in SceneGraph components?

Fri May 12, 2017 7:06 pm

Copying the function you need into the component/duplicating it works.
 
tmat1075
Posts: 22
Joined: Mon Apr 17, 2017 9:35 am

Re: Accessing global functions in SceneGraph components?

Mon May 15, 2017 8:12 am

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> 
 
User avatar
RokuNB
Posts: 108
Joined: Fri Mar 31, 2017 2:22 pm

Re: Accessing global functions in SceneGraph components?

Mon May 15, 2017 10:18 am

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.
 
johnmarsden
Topic Author
Posts: 36
Joined: Wed Nov 18, 2015 1:37 pm

Re: Accessing global functions in SceneGraph components?

Mon May 15, 2017 2:55 pm

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?
 
User avatar
RokuNB
Posts: 108
Joined: Fri Mar 31, 2017 2:22 pm

Re: Accessing global functions in SceneGraph components?

Mon May 15, 2017 5:57 pm

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
Topic Author
Posts: 36
Joined: Wed Nov 18, 2015 1:37 pm

Re: Accessing global functions in SceneGraph components?

Tue May 16, 2017 4:03 pm

Ah yes, I'm seeing that now. Stripped away after passing them in :(  That's unfortunate.

Who is online

Users browsing this forum: gabek and 3 guests