Built-in functions – BrightSign BrightScript 2 Reference Guide User Manual

Page 33

Advertising
background image

33

Built-In Functions

BrightScript has a small number of built-in, module scope, intrinsic functions. They are
the following.

Type(variable) As String

Returns the type of a variable and/or object. See the Roku Object specification for a list
of types. For example:

Print type (5)

Rnd(0) As Float

Rnd(range As Integer) As Integer

Generates a pseudo-random number using the current pseudo-random "seed number"
(generated internally and not accessible to user). RND may be used to produce random
numbers between 0 and 1, or random integers greater than 0, depending on the argument.

RND(0) returns a float value between 0 and 1.
RND(integer) returns an integer between 1 and integer inclusive . For example, RND(55)
returns a pseudo-random integer greater than zero and less than 56.

Box(x as Dynamic) as Object

Box() will return an object version of an intrinsic type, or pass through an object if given
one. For example, in places where you want to use string object functions on a string,
you can:

str=” this is a string ”
print box(str).trim()
bo = box(“string”)
bo=box(bo) „ no change to bo
print bo.md5()

Run(filename As String, Optional Args…) As dynamic

The run command will run a script from a script. Args may be passed to the scripts
Main() function, and the called script may return arguments.

Example:

Sub Main()

Run("test.brs")
BreakIfRunError(LINE_NUM)
Print Run(“test2.brs”, “arg 1”, “arg 2”)

stop

End Sub

Sub BreakIfRunError(ln)

Advertising