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: 
ioan
Level 7

[SOLVED] Cannot share functions between brs files in source folder

I created yesterday a new .brs files in my /source folder and it seems that the functions defined in this file cannot be seen by other .brs files from that same folder.
function sendRTSPCommand(socket, commandArray, mtop) is defined in rtsp.brs and is located in /source folder, but when I try to call the function in stream.brs (which is in the same folder), I get the following error:

039:*   sendRTSPCommand(socket, commandArray, mtop) 
040:  end sub
Function Call Operator ( ) attempted on non-function. (runtime error &he0) in pkg:/source/stream.brs(39)


This doesn't happen with other files that I have there, is just with this, the last one. Also, I checked and the file is in the zip archive that is uploaded to roku.

Any ideas what could be wrong?
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
10 Replies
joetesta
Level 10

Re: Cannot share functions between brs files in source folder

Assuming you're working in RSG, you probably need to include the new file in the XML of any other files where you intend to use its functions;
<script type = "text/brightscript" uri = "pkg:/components/VideoTheater.brs" />


https://sdkdocs.roku.com/display/sdkdoc/script
aspiring
0 Kudos
ioan
Level 7

Re: Cannot share functions between brs files in source folder

"joetesta" wrote:
Assuming you're working in RSG, you probably need to include the new file in the XML of any other files where you intend to use its functions;
<script type = "text/brightscript" uri = "pkg:/components/VideoTheater.brs" />


https://sdkdocs.roku.com/display/sdkdoc/script

The files that I'm trying to share the functions between are just brs files with utility functions with no xml equivalent and they are all in the /source folder. The old ones can share the functions fine between them, just the last one that I created cannot be seen by the other files from the same folder.
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
Roku Employee
Roku Employee

Re: Cannot share functions between brs files in source folder

"ioan" wrote:
[The files that I'm trying to share the functions between are just brs files with utility functions with no xml equivalent and they are all in the /source folder. The old ones can share the functions fine between them, just the last one that I created cannot be seen by the other files from the same folder.

i would venture a guess the .brs file was not included in the build.
to troubleshoot, just check in console when the error happens what's in sendRTSPCommand (? sendRTSPCommand); if it's a function, try calling it with params and so on... you'll figure out what's happening soon enough
0 Kudos
ioan
Level 7

Re: Cannot share functions between brs files in source folder

"RokuNB" wrote:

i would venture a guess the .brs file was not included in the build.
to troubleshoot, just check in console when the error happens what's in sendRTSPCommand (? sendRTSPCommand); if it's a function, try calling it with params and so on... you'll figure out what's happening soon enough


The file IS in the build. I checked and the file, is just like the other ones in the zip archive in the /source directory (I unzipped to make sure is there). After uploading the zip file to Roku device, I get the error above. If I move all the functions from this file to another one that already works, the functions are found. If I copy the functions to another file AND I leave the original file in there, I get the error that the functions are redefined... so the brs is in there, just cannot share it's functions...


------ Compiling dev 'IP Camera Viewer Pro' ------
*** ERROR compiling /pkg:/source/rtsputils.brs:
SUB or FUNCTION defined twice. (compile error &had) in pkg:/source/rtsputils.brs(2) 'sendRTSPCommand'
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
ioan
Level 7

Re: [SOLVED] Cannot share functions between brs files in source folder

joetesta was right... all those libraries of functions end up used in a task, even if I don't call them directly in the task, so I had to include the .brs file in the XML file that belongs to the task
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
Roku Employee
Roku Employee

Re: [SOLVED] Cannot share functions between brs files in source folder

There two different models of inclusion:

  • main() thread execution sees all functions defined in source/.../*.brs (implicit inclusion)

  • component threads only see the functions from explicitly <script/> included files
0 Kudos
mco_dolo
Level 7

Can't call functions in source folder other than in main.brs

Project structure:
/source - A.brs, B.brs. main.brs

I can call functions from A.brs and B.brs in main.brs, but I can't call functions from B.brs in A.brs and vice versa. Is it suppose to be like that? Thanks.
0 Kudos
joetesta
Level 10

Re: Can't call functions in source folder other than in main.brs

check out this recent post about the same issue 
hope it will help,
Joe
aspiring
0 Kudos
Roku Employee
Roku Employee

Re: [SOLVED] Cannot share functions between brs files in source folder

Merged the two. Thank you for the pointer @joetesta !
0 Kudos