Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
greubel
Visitor

Task subroutine

Can Task code call a subroutine in Main brs code ?
0 Kudos
5 REPLIES 5
renojim
Community Streaming Expert

Re: Task subroutine

Yes. I believe you can call any subroutine in any file in your source directory.
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
greubel
Visitor

Re: Task subroutine

This isn't true. Here is a call to XR() which fails. It is defined in the main.brs code

Current Function:
018:  Sub Activate()
019:*    XR(100)
020:     x = m.top.Input.data
021:  ? "Task in = " x
022:     sleep(100)
023:  ? "Task exit after 100 milliseconds"
Function Call Operator ( ) attempted on non-function. (runtime error &he0) in pkg:/components/Task.xml(19)
019:    XR(100)
0 Kudos
joetesta
Roku Guru

Re: Task subroutine

afaik you should put the sub in a separate file (eg "mySubs.brs")
and include it from your task's XML; something like:
<script type="text/brightscript" uri="pkg:/source/mySubs.brs" />


You could also have a subfolder of /source/ with a bunch of such subs separated out to be included as needed.
aspiring
0 Kudos
greubel
Visitor

Re: Task subroutine

Good idea. Thanks !
0 Kudos
renojim
Community Streaming Expert

Re: Task subroutine

"joetesta" wrote:
afaik you should put the sub in a separate file (eg "mySubs.brs")
and include it from your task's XML; something like:
<script type="text/brightscript" uri="pkg:/source/mySubs.brs" />


Ah, that's it!  Sorry greubel.  I knew I was calling subroutines in other source files, but I forgot that I listed the file in the XML.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.