Your Digital Media Has Never Looked So Good

 
greubel
Topic Author
Posts: 708
Joined: Wed Feb 10, 2010 4:21 pm

Task subroutine

Tue Dec 18, 2018 12:58 pm

Can Task code call a subroutine in Main brs code ?
 
renojim
** Valued Community Member **
Posts: 3481
Joined: Mon Feb 15, 2010 1:35 pm

Re: Task subroutine

Wed Dec 19, 2018 9:36 am

Yes. I believe you can call any subroutine in any file in your source directory.
 
greubel
Topic Author
Posts: 708
Joined: Wed Feb 10, 2010 4:21 pm

Re: Task subroutine

Thu Dec 20, 2018 9:52 am

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)
 
joetesta
Posts: 790
Joined: Wed Apr 20, 2011 11:48 am

Re: Task subroutine

Thu Dec 20, 2018 12:59 pm

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
 
greubel
Topic Author
Posts: 708
Joined: Wed Feb 10, 2010 4:21 pm

Re: Task subroutine

Thu Dec 20, 2018 4:38 pm

Good idea. Thanks !
 
renojim
** Valued Community Member **
Posts: 3481
Joined: Mon Feb 15, 2010 1:35 pm

Re: Task subroutine

Thu Dec 20, 2018 7:04 pm

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

Who is online

Users browsing this forum: No registered users and 5 guests