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: 
ahmednuaman
Visitor

The 'main' function

I'm new to roku development and just had a few questions regarding the code and file structure and the execution process at runtime:

1. How does file linking work? I've had a look at some of the example apps, some contain multiple files but I can't see a clear way of how they files are linked or functions are imported.
2. Is there a base script and function that sets everything off? Some apps use Sub Main but some don't; how does the platform know where the app's start point is?
0 Kudos
5 REPLIES 5
RokuMarkn
Visitor

Re: The 'main' function

1. Nothing special needs to be done to use multiple files. All .brs files in your source directory are compiled together.
2. The entry point is RunUserInterface. If there is no such function, it uses Main. If the channel has a screensaver, there are one or two special entry points, RunScreenSaver to run the screen saver, and RunScreenSaverSettings to run the settings screen for the screen saver, if there is one.

--Mark
0 Kudos
ahmednuaman
Visitor

Re: The 'main' function

Thanks! So is it safe to assume that I ought to start all apps with `Sub Main` function? Are there any MVC/MVVM/etc examples?
0 Kudos
btray77
Visitor

Re: The 'main' function

No MVC or MCCM examples.. The language isn't really setup to easily do that, but you can abstract some of the "view" aspects away using XML and reading it in and determining what goes where.
0 Kudos
ahmednuaman
Visitor

Re: The 'main' function

"btray77" wrote:
No MVC or MCCM examples.. The language isn't really setup to easily do that, but you can abstract some of the "view" aspects away using XML and reading it in and determining what goes where.


Ok, is it then possible to organise my code within folder under the `source` folder? Or do all the code files have to be at the top level in order to be loaded by the interpreter?
0 Kudos
RokuJoel
Binge Watcher

Re: The 'main' function

You can organize your .brs files within your project any way you want, source in any .brs file within your project should be compiled the same as if it was all in one .brs file. You can have folders within the source folder containing .brs files and folders within those folders. Not sure how deep you can go with that, and too many might slow down the compilation process. I've found that breaking a project up into a large number of .brs files does not compress as well as just a few .brs files, but storing all code within one .brs file doesn't compress that well either when you zip it.

- Joel
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.