Roku Developer Program

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

Referencing a function from a brs file from another brs file?

What is the best way for one BRS file (that does not have an associated XML file) to reference a function within another BRS file (that does have an associated XML file)?
0 Kudos
5 Replies
EnTerr
Level 9

Re: Referencing a function from a brs file from another brs file?

There is no "best way". It either works or it doesn't Smiley Happy
Be more specific!
The typical Brightscript behavior is that all files in /source are included automatically and visible (i.e. the main thread).
In XMLophony though, only the explicitly <script> included sources are visible.
0 Kudos
jaxim
Level 7

Re: Referencing a function from a brs file from another brs file?

In A.brs file (located under the folder: "/components/screens/A), I have the following function: 
Function foo()
  ? 'foo()$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
end Function


In a different file (B.brs located under the folder "/source"), I try to make reference to the foo() method like so:
foo()


But this causes a runtime error.

What am I doing wrong? How do I ensure the B.brs file has a reference to the A.brs file.
0 Kudos
softworkz
Level 7

Re: Referencing a function from a brs file from another brs file?

You need to put an additional <script> tag into your component xml file
0 Kudos
jaxim
Level 7

Re: Referencing a function from a brs file from another brs file?

But I want to make a reference from B to A. B does not have a corresponding XML file.
0 Kudos
EnTerr
Level 9

Re: Referencing a function from a brs file from another brs file?

"jaxim" wrote:
But I want to make a reference from B to A. B does not have a corresponding XML file.

Who is executing or including the B file?
If the functions in B.brs are executed as part of main() thread, so should A.brs file be part of /source.

Yes, the mating between RSG and  Brightscript has been grossly mismanaged (or "fork"ed up, if you will)... but we all knew that already.
0 Kudos