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

calling function located in different file

Hello,
I am a newbie and have aquestion about BScript, If I have a function in play.brs as:
function play ()
print "this is just to see if the function call works"
end function

and I am calling it from appMain.brs as follows:
play()

I get the following error in console debug:
Function Call Operator ( ) attempted on non-function. (runtime error &he0) in ...QpQxj/pkg:/source/appMain.brs(9)

what am I doing wrong ?
I appreciate the help.
0 Kudos
4 Replies
SkipFire
Level 7

Re: calling function located in different file

If that is the exact script then my guess your error is on the function line as it looks like you have a space between play and (). Calling functions across files does work fine and does not need anything extra, if you equate it to other languages everything compiles into one class (just a very rough analogy).
0 Kudos
Roku Employee
Roku Employee

Re: calling function located in different file

FYI, all your brightscript files need to end with .brs and they should all be within the source folder in your package. If the files do not have a .brs extension then the contents will not be interpreted as brightscript, perhaps something like that is why it isn't finding the play function. A space between play and () doesn't matter

- Joel
0 Kudos
aaCpp
Level 7

Re: calling function located in different file

skipfire, you are absolutely right the space was the culprit, I did not think it would matter.
0 Kudos
dinamovera
Level 7

Re: calling function located in different file

I have a similar situation, I'm trying to call a function from main.brs

here is my folder structure:

components > scenes > mainScene.brs
source > main.brs

from main.brs I'm trying to call a function within mainScene.brs
But I'm getting an error 

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo} span.s1 {font-variant-ligatures: no-common-ligatures}

all Operator ( ) attempted on non-function. (runtime error &he0) in pkg:/source/main.brs(64)
064:         playGameById()

mainScene.brs function I'm trying to call

Function playGameById() as Void
   print "playGameById"
   print id
End Function[/color]

main.brs function where I'm trying to call mainScene function

Sub deepLink(args)
   if (args.mediaType <> invalid) and (args.contentID <> invalid)
       print args.mediaType
       print args.contentID
       playGameById()
   else
       print 'do nothing'
   end if
End Sub[/color]
0 Kudos