Brightscript is a BASIC-like language developed for the Roku and Brightsign hardware platforms.
Brightscript is a BASIC-like language developed for the Roku and Brightsign hardware platforms.
Brightscript is single threaded, procedural language with some object oriented features. It lacks support for Classes and Inheritance. Brightscript allows only one global variable, "m". However m can contain a complex global data structure. Arrays are one-dimensional; however, you can create arrays of arrays.
There are two primary types of array variables: roArray and roAssociativeArray.
Arrays can be defined with a CreateObject statement or using shorthand
varname=createobject(roArray,5,true)
creates an expandable array containing 5 elements. Alternatively:
varname=[]
creates an empty, but expandable Array.
roAssociativeArrays can also be described as a data dictionary. They can be created as follows:
varname=createobject(roAssociativeArray)
or
varname={}
using curly brackets.
To assign values to an Array:
varname=[100,200,"ABCD","ZYXW"]
or
varname[0]=100
varname[1]=200
varname[2]="ABCD"
varname[3]="ZYXW"
to assign values to an AssociativeArray or "AA":
varname={name:"John Smith",address:"1023 West Alameda",telephone:"415-555-1212"}
or
varname={}
varname["name"]="John Smith"
varname["address"]="1023 West Alameda"
varname["telephone"]="415-555-1212"
a mode which allows almost any ASCII character to be used as a key, or, using dot notation:
varname={}
varname.name="John Smith"
varname.address="1023 West Alameda"
varname.telephone="415-637-1283"
Aside from the usual text and numeric manipulation functions, Brightscript also has specialized objects that can be created, such as "roAudioPlayer", "roVideoPlayer" and many different display screen types, the most commonly used are "roPosterScreen" and "roGridScreen". These objects are created and assigned a reference variable in the following manner:
screen=CreateObject("roPosterScreen")
It could then be populated:
item1={ShortDescriptionLine1:"item 1"}
item2={ShortDescriptionLine1:"item 2"}
item3={ShortDescriptionLine1:"item 3"}
content=[item1,item2,item3]
screen.setcontentlist(content)
Note that item 1 2 and three are roAssociativeArrays and that content is an roArray containing three roAssociativeArrays.
To display the screen:
screen.show()
Instead of a REM statement, Brightscript uses the single quote:
'this is a comment
Program Execution statements include:
- For / End For / Exit for
- While / End While / Exit While
- If / Then / Else / Else If / End If
Brightscript is not Case Sensitive for the most part; however, string comparisons and AssociativeArray keys can be case sensitive.
For more information on Brightscript, please see the following links:
BrightScript Language Reference
Roku Developer Program signup link
And the frequently helpful Roku Developers Forum