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

Task subroutine

Can Task code call a subroutine in Main brs code ?
0 Kudos
5 Replies
renojim
Level 8

Re: Task subroutine

Yes. I believe you can call any subroutine in any file in your source directory.
0 Kudos
greubel
Level 7

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 10

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 7

Re: Task subroutine

Good idea. Thanks !
0 Kudos
renojim
Level 8

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
0 Kudos