BrightScript Language for Roku

28 / Jun / 2016 by Upasana Chauhan 1 comments

Today we will learn basics of BrightScript language.

What is BrightScript language
As the name suggests BrightScript language is a scripting language, the main purpose of its development was for Roku device. In our first blog we have already discussed what Roku is, Introduction and setup in Roku TV The BrightScript language is written in C, though it’s syntactically does not follow C, it resembles more like Python/Ruby/Lua/Basic. BrightScript program runs over its engine above the kernel layer in Roku.

Why it is important to learn
It is important to learn BrightScript language because Roku supports only this language for developing apps/channnels. BRS is not a case dependent language.

IDE for BrightScript language
There is one popular IDE for Roku, which is Eclipse. On there SDK documentation page you will find below mentioned content.

BrightScript Plugin Update
Roku has released a completely updated version of the Eclipse BrightScript Plugin. The new plugin required Eclipse 4.5 (Mars) as a minimum, DLTK 5, and Java 8. The update site URL for the plugin is now . The previous version at is no longer supported. For complete details see this article on the Roku developer blog.

Basics of BrightScript language

1. Function
To start with any logic we need to create either a function or sub. The Sub is discussed below.
The syntax of function is

[code]Function functionName(parameter1 as type1, parameter2 as type2) as type
returns obj
End Function[/code]

Here, every case needed to be end by END tag. The parameter1, parameter2 are optional. Type could be String, Integer, Boolean, default, invalid depending on situation. Function returns any object based on type declared.

2. Sub
The only difference in function and sub is there is no return type.
The syntax of function is

[code]Sub functionName(parameter1 as type1, parameter2 as type2)
End Sub[/code]

3. If/Else/End if
Conditional statement used in Roku, with the following syntax.

[code]If(condition1) then
else if (condition2)
else
end if[/code]

This is a normal syntax used for if/else clause. THEN is not compulsary to mention, but its a good practice to write.

4. For
Looping statements used in Roku is FOR.
The syntax for FOR is,

[code]For i = 0 to 10
Print i
i = i + 1
End For[/code]

5. Return
Return statement is used to return any value from function.

6. While
While in Roku has a significant inportance. For any screen to remain visible in Roku, while statment is used.

[code]While (true)
msg = wait (0, port)
if type(msg) = “anyScreenEvent” then
//do task
//exit while
end if
end while[/code]

Here, the control will remain in while section till the time Exit while is not called in any of the case. “anyScreenEvent” will be discussed in our next blog.

7. Type ( value )
It returns the type of the value, like, invalid, int, boolean, string, or any customized type created by developer.

8. Print
It prints any value on console.

[code]Print anyValue[/code]

9. m.value (Global)
This is used to declare global values in BrightScript language. Values declared with m tag can be accessed inside function or outside brs class also.

10. invalid
This is a important type user in BrightScript langugae. For easy interpretation we can assume it as null. Any value with type invalid will crash your code if not handled well. Therefore it is important to apply cases like,

[code]if(parameter invalid)
Print “hello I am not invalid”
End if[/code]

11. ParseJson
This function will parse a string formatted according to RFC4627 and return an equivalent Brightscript object. If the string is not syntactically correct, Invalid is returned.

[code]Function ParseJson (jsonString As String) As Object
End Function[/code]

12. Wait
This function waits on Object that are “writable” (those that have a MessagePort interface).
Wait() returns the event object that was posted to the message port.
If timeout is zero, “wait” will wait forever.
Otherwise, Wait will return after timeout milliseconds if no messages are received. In this case, Wait returns a type “invalid”.

[code]Function Wait (timeout As Integer, port As Object) As Object
End Function[/code]

This blog helps you in understanding basic coding standards used in BrightScript language. Using these we can build our first basic Roku App.

In next blog we will look into problems and solutions faced while implementing features like Ads, GA, Makefile, parse HTML in Roku.

FOUND THIS USEFUL? SHARE IT

comments (1 “BrightScript Language for Roku”)

Leave a Reply to Ramesh Cancel reply

Your email address will not be published. Required fields are marked *