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

**URL:** <https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990>\
**Category:** Archived\
**Tags:** roku-developer-program\
**Created:** [January 8, 2018, 6:50pm UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990 "2018-01-08T18:50:45Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ioan](https://avatars.discourse-cdn.com/v4/letter/i/bc79bd/32.png) [@ioan](https://forum.developer.roku.com/u/ioan)\
**Post date:** [January 8, 2018, 6:50pm UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/1 "2018-01-08T18:50:45Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![joetesta](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@joetesta](https://forum.developer.roku.com/u/joetesta)\
**Post date:** [January 8, 2018, 7:02pm UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/2 "2018-01-08T19:02:29Z")

</div>

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;

```auto
<script type = "text/brightscript" uri = "pkg:/components/VideoTheater.brs" />

```

[https://sdkdocs.roku.com/display/sdkdoc/script](https://sdkdocs.roku.com/display/sdkdoc/script)

---

<div class="post-metadata">

**Author:** ![ioan](https://avatars.discourse-cdn.com/v4/letter/i/bc79bd/32.png) [@ioan](https://forum.developer.roku.com/u/ioan)\
**Post date:** [January 8, 2018, 7:12pm UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/3 "2018-01-08T19:12:52Z")

</div>

> “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;
> 
> ```auto
> 
> ```

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.

---

<div class="post-metadata">

**Author:** ![NB](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@NB](https://forum.developer.roku.com/u/NB)\
**Post date:** [January 8, 2018, 9:24pm UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/4 "2018-01-08T21:24:51Z")

</div>

> “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

---

<div class="post-metadata">

**Author:** ![ioan](https://avatars.discourse-cdn.com/v4/letter/i/bc79bd/32.png) [@ioan](https://forum.developer.roku.com/u/ioan)\
**Post date:** [January 8, 2018, 9:59pm UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/5 "2018-01-08T21:59:17Z")

</div>

> “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…

```auto
------ 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'

```

---

<div class="post-metadata">

**Author:** ![ioan](https://avatars.discourse-cdn.com/v4/letter/i/bc79bd/32.png) [@ioan](https://forum.developer.roku.com/u/ioan)\
**Post date:** [January 8, 2018, 10:09pm UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/6 "2018-01-08T22:09:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![NB](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@NB](https://forum.developer.roku.com/u/NB)\
**Post date:** [January 9, 2018, 12:52am UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/7 "2018-01-09T00:52:47Z")

</div>

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 included files

---

<div class="post-metadata">

**Author:** ![mco\_dolo](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@mco\_dolo](https://forum.developer.roku.com/u/mco_dolo)\
**Post date:** [January 25, 2018, 11:47pm UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/8 "2018-01-25T23:47:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joetesta](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@joetesta](https://forum.developer.roku.com/u/joetesta)\
**Post date:** [January 27, 2018, 8:28am UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/9 "2018-01-27T08:28:42Z")

</div>

check out [this recent post about the same issue](https://forums.roku.com/viewtopic.php?f=34&t=110670)  
hope it will help,  
Joe

---

<div class="post-metadata">

**Author:** ![NB](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@NB](https://forum.developer.roku.com/u/NB)\
**Post date:** [January 27, 2018, 6:05pm UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/10 "2018-01-27T18:05:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mco\_dolo](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@mco\_dolo](https://forum.developer.roku.com/u/mco_dolo)\
**Post date:** [January 29, 2018, 10:05pm UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/11 "2018-01-29T22:05:02Z")

</div>

Hmm, I didn’t understand the solution,  
In /source I have A.brs, B.brs, and main.brs. For A.brs to call function from B.brs, I have to create A.xml and import B.brs?  
I don’t think A.xml will get initialized unless you call CreateObject(“A”) right??

If main.brs can already statically call methodFromA() so I don’t really know why you would need to call CreateObject(“A”).  
Sorry, kinda new to this.

---

<div class="post-metadata">

**Author:** ![jcarlosr17](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@jcarlosr17](https://forum.developer.roku.com/u/jcarlosr17)\
**Post date:** [April 21, 2021, 10:53pm UTC](https://forum.developer.roku.com/t/solved-cannot-share-functions-between-brs-files-in-source-folder/5990/12 "2021-04-21T22:53:53Z")

</div>

I think the author of the question ended up copying one brightscript into the other, instead of actually importing.

I have a very large .brs file and would like to split in multiple scripts.

Is there a way to have 1 .brs file that imports others into it? And so finally import a single .brs file while keeping things organized?
