Description of Various Brightscript Language References

Posted By Rupesh Sharma | 20-Oct-2018

  Basic BrightScript Statement

We will discuss here a basic brightscript statement in order to build Roku application.

BrightScript is a powerful scripting language that supports a lightweight library of brightscript objects, that enables it to build media and networked applications for embedded devices. Various BrightScript Language references:

1. Identifiers: It specifies providing names of variables, functions, object or functions etc.

The following rules are followed for identifiers

  • it must start with an alphabetic character (a-z) or “_”
  • it may consist of alphabetic characters, numbers or symbol(“_”)
  • not case sensitive
  • can have any length
  • should not use reserved words
  • may end with designator character(optional) like(% for integer, $ for string, ! for float, # for double) .

2. Comments: We can use an apostrophe (‘) or the statement REM for commenting out the statements or code in the syntax. For example: Adding an explanatory description in order to brief it for reading purpose -

             centX=(230-examp.width)/2     ‘ control horizontal alignment of button group
             centY=(230-examp.height)/2     ‘ control vertical alignment of button group

3. Types: Brightscript uses dynamic typing i.e variable can also be determined at runtime. Now, brightscript also has declared types which means the variable can also be specified for containing a value of a specific type.

The various supported types in brightscript are:

  • Boolean- Either false or true Integer- 32 bit signed integer number
  • LongInteger- 64 bit signed integer number
  • Float- 32 bit IEEE floating point number
  • Double- 64 bit IEEE floating point number
  • String- A sequence of Unicode characters.
  • Object- A reference to components of brightscript. For example- “roArray”, “roList”, “roAssociativeArray” etc
  • Function- These are an intrinsic type, can be stored in variables and passed to functions.
  • Interface- A brightscript component.
  • Invalid- This type has only one value: invalid.

4. Function Literals:

Array literals: The array operator[] is used to declare an array to store values.

newArray=[]                                           ‘ an empty array
newArray=[2,4,8,16]                              ‘ array of four members
newArray=[x+10, 3<>2, false]               ‘ array of three members 

An array can be specified in a multi-line form

    “table” ]

Associative Literals: The associative array can be defined by using {} operator. It can contain expressions of literals

rr={key1: “value1”, key2: “9090”, key3: 5+6}

Associative arrays can also be specified in a multi-line form

  MyNewFun: xFunction
  MyVal1 : “my new value”

5. Function: The function call operator “()” is used to call a function. Example-

   function showNumber() ass Integer
          return 120
   end function
   print showNumber()
   numbers = showNumber
   print numbers()
   arr[1] = numbers	
   print arr[1]()

In this way the language references are used to specify syntax in brightscript.

Request for Proposal

Recaptcha is required.

Sending message..