Questions tagged [brightscript]

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:

Roku Developer Guide

BrightScript Language Reference

Roku Developer Program signup link

And the frequently helpful Roku Developers Forum

415 questions
3
votes
2 answers

Roku: Is it standard practice to unobserve unused variables after observing them?

Say I was observing a variable m.someObject.observeField("content", "onContentChanged") after a certain period of time I no longer need m.someObject. Do I need to cleanup and call m.someObject.unobserveField("content") or can I just leave it?
mco
  • 1,809
  • 15
  • 31
3
votes
2 answers

Roku Ad Framework : Failed to create mediaPlayer

RAF fails to render the mediaPlayer for ads and idles on the buffering screen. I can still exit video playback without issues. This is when I make the call to showAds(). if adPod <> invalid AND adPod.count() > 0 ? "Playing pre-roll ad" …
3
votes
4 answers

Disabling remote (trick play) buttons in a Roku live streaming application video node?

I'm having trouble disabling the remote control buttons like "fast forward", "pause", etc. in my Roku application. It is a very simple application that just has the one main scene, which only creates a video node that plays a live stream of our…
Anon Mouse
  • 31
  • 2
3
votes
1 answer

How to use Interface in brightscript for functions

I want a function need to be called using interface-implementation model. I have read that roku has provision to have a function inside the interface portion in brightscript's document. So I tried but failed. Could anyone help me?
ganka
  • 191
  • 1
  • 11
3
votes
3 answers

How do I call XML code from Brightscript for a Roku Channel?

I'm trying to populate a Label List using the below XML Roku Channel, Scenegraph code. I'm getting these errors: BRIGHTSCRIPT: ERROR: roSGScreen: creating MAIN|TASK-only component failed on RENDER thread:…
neowinston
  • 7,584
  • 10
  • 52
  • 83
3
votes
2 answers

Creating a page for date entry for Roku?

I'm working on a Roku app and we want the user's date of birth. Trying not to get too complex on the parsing end (so would prefer to not just have a text box where the user can enter whatever they want). I looked into using a roPinEntryDialog, but…
Cassidy
  • 3,328
  • 5
  • 39
  • 76
3
votes
3 answers

Is it possible to assign an anonymous function to a global associative array property?

New to roku/brightscript development: Is it possible to add an object to the global associative array (accessible by all components), that has a method defined as one of the properties, and call that method? Main.brs: function Main() init() end…
neoRiley
  • 465
  • 6
  • 11
3
votes
1 answer

How do you get error code from syncronous roUrlTransfer call

I have this piece of code that gets and parses JSON from an HTTPS url: Function GetJson(sUrl As String) As dynamic if sUrl = invalid return invalid httpGet = CreateObject("roUrlTransfer") httpGet.SetURL(sUrl) …
rynop
  • 50,086
  • 26
  • 101
  • 112
3
votes
2 answers

How to Check if an Array Contains a Value in brightscript Efficiently?

Given an roArray: found = CreateObject("roArray", 0, true) found.push("a") found.push("b") found.push("c") What is the best way to check if value s = "s"?
Ronald Chu
  • 33
  • 1
  • 4
3
votes
2 answers

Change the default timeout for CURL request from roku

The AsyncPostFromString method from roUrlTransfer object generates a CURL request with a timeout of 30secs. i.e port = CreateObject ("roMessagePort") ut = CreateObject ("roUrlTransfer") ut.setMessagePort(port) ut.AsyncPostFromString(data) Does…
André Leal
  • 186
  • 1
  • 8
3
votes
4 answers

Find Date Difference in BrightScript

I have an issue with datetime. I have two strings. e.g 24-9-15 and 2-10-15. Both are two strings. I want to find out the difference (in days) between them. Can you please help me out?
Developer
  • 103
  • 12
3
votes
2 answers

How to host an htm5 app on a private channel on "Roku"?

I am just starting with development for "Roku". I want to know How can I host an html5 app on private channel on Roku. To get started I have created a a private roku channel from https://www.instanttvchannel.com and have even installed on my roku…
G droid
  • 956
  • 5
  • 13
  • 36
3
votes
3 answers

Background color of roMessageDialog

In Roku BrightScript, is there any way to change the background color of popup dialogs such as roMessageDialog to a dark blue color, instead of the default gray? It is possible to change the text color through the attributes DialogBodyText and…
Pieter Siekerman
  • 461
  • 3
  • 14
3
votes
1 answer

How does the roTextureManager image cache behave?

Does the roTextureManager clear or replace bitmaps in its cache automatically when it sees that it is running out of memory? I cannot seem to find any good answer to this.
Karim
  • 415
  • 6
  • 14
3
votes
1 answer

URL Encoding a variable for a web service call on Roku

I need to URL encode a variable that is being passed into a web service. testcategory = "Action and Adventure" jsonRequest = CreateObject("roUrlTransfer") jsonRequest.SetURL("http://myurl.com/?method=getRokuCategorizedSeriesListing&category=" +…
Josh Scott
  • 3,790
  • 7
  • 29
  • 31
1
2
3
27 28