Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
greubel
Level 8

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
Level 8

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
Level 11

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
Level 8

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