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: 
btpoole
Channel Surfer

Not Finding my Function

At one time I put a function to make roUrlTransfer in my main.brs. To clean up the main.brs I created another brs in the source folder called utilis.brs and moved the function to the utils.brs. Now when I run the app and the call to the function in the main.brs is made,  the function in the utils.brs is not found.  I am not understanding why, I thought it would find the function in any brs file.
0 Kudos
11 REPLIES 11
RokuNB
Roku Guru

Re: Not Finding my Function

That does work.
Something else is at play here - maybe the new file is not included in the bundle or you have renamed the function (i.e. the name called in main is different from the name defined in utils.brs)
0 Kudos
Komag
Roku Guru

Re: Not Finding my Function

Yeah it definitely should work - I have about a dozen .brs files
0 Kudos
btpoole
Channel Surfer

Re: Not Finding my Function

Thanks, sometimes the obvious is the hardest to see. Had added "s" to function name and didn't realize it.
0 Kudos
btpoole
Channel Surfer

Re: Not Finding my Function

I actually thought I had fixed this issue but seems not to be the case. I have noticed that when the app starts it performs a urlTransfer to check a value from the server. If all is good it proceeds to the next step where it checks if user info exist, if not it goes to a task to get certain user info. Once the user info is obtained, it basically starts from the top of the code. The problem occurs at this point.  Here is the basic code to start.

Sub RunUserInterface()
Print "RUNUSERINTERFACE"
screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)
scene = screen.CreateScene("BusySpinnerExample")
screen.show()
url="http://xxxxxx.vvvvv.cc/backcheck.txt"
backcheck=urlTransferServer(url)
backcheck=backcheck.toint()
if backcheck <> 0
presetup()
else
kickout()
end if
end sub

The urlTransferServer function is saved in a utilies.brs file located in the source folder. On the initial start the urlTransferServer is found and processed. Once the code reaches the presetup() (located in the main.brs) code and the user inputs info, the RunuserInterface() is called again. At this point I get the error that "Function Call Operator () attempted on non-function". In other words it is no longer recognizing the urlTransferServer as a function. If I place the urlTransferServer function in the main.brs, all works as expected. I could work around the error but would really like to know why it sees the function initially but not later. Would it be that the user input task falls in a folder outside of the source folder?
0 Kudos
destruk
Binge Watcher

Re: Not Finding my Function

Why exactly would you call runuserinterface again?  btw UrlTransfer isn't allowed to run in the render thread in SceneGraph, so You'll probably want to ultimately move the code to the end in presetup is it?
A better flow would be - 
check if the server is up and accessible
If the server is down, exit
Get the user information you need from the server
If the user exists start main program

If the user doesn't exist, run through the linking and account setup
If the account setup is successful then you already have the user information you needed and the server is accessible so start the main program

If the account setup failed, exit.

screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)
scene = screen.CreateScene("BusySpinnerExample")
screen.show()
0 Kudos
destruk
Binge Watcher

Re: Not Finding my Function

As soon as you have moved to a scenegraph state, rourltransfer is only allowed to run in a task node.  So you need to either close the scenegraph thread to get back to your main.brs, or use a task node if you need rorultransfer later.
0 Kudos
btpoole
Channel Surfer

Re: Not Finding my Function

Thanks, kinda what I had concluded but wasn't sure that's what was happening.
0 Kudos
btpoole
Channel Surfer

Re: Not Finding my Function

"destruk" wrote:
As soon as you have moved to a scenegraph state, rourltransfer is only allowed to run in a task node.  So you need to either close the scenegraph thread to get back to your main.brs, or use a task node if you need rorultransfer later.

destruk, this may sound like a really dumb question, but how do you close the scenegraph thread to get back to the main.brs?
0 Kudos
destruk
Binge Watcher

Re: Not Finding my Function

Most likely -
In your main.brs you have a wait statement and a while routine.

While TRUE
msg=Wait(0,port)
print"------------------"
Print"msg=";msg
End While

What if you put code after that point?  When scenegraph closes it would then resume the main.brs thread there.
Standard rules about having a facade screen open to prevent the app from terminating apply.
0 Kudos