beautypg.com

Global functions – BrightSign BrightScript 2 Reference Guide User Manual

Page 35

background image

35

Global Functions

BrightScript has a set of standard, module scope, functions. These functions are stored in
the global object. If the compiler sees a reference to one of the global functions, it directs
the runtime to call the appropriate global object member.

Sleep(milliseconds As Integer) As Void

This function causes the script to pause for the specified time, without wasting CPU
cycles. There are 1000 milliseconds in one second.
Example:

sleep(1000) „ sleep for 1 second
sleep(200) „ sleep 2/10 of a second
sleep(3000) „ sleep three seconds

Wait (timeout As Integer, port As Object) As Object

This function waits on objects that are “waitable” (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 for ever. Otherwise, Wait will return after timeout
milliseconds if no messages are received. In this case, Wait returns a type “invalid”.

Example:

p = CreateObject("roMessagePort")
sw = CreateObject("roGpioControlPort")
sw.SetPort(p)
msg=wait(0, p)

print type(msg) „ should be roGpioButton
print msg.GetInt() „ button number

CreateObject(name As String) As Object

Creates a Roku Object of class name specified. Return invalid if the object creation
fails. Some Objects have optional parameters in their constructor that are passed after
name. Example:

sw = CreateObject("roGpioControlPort")
serial = CreateObject(“roSerialPort”, 0, 9600)

GetInterface(object As Object, ifname As String) As Interface

Each Roku Object has one or more interfaces. This function returns a value of type
“Interface”.

Note that generally Roku Objects allow you to skip the interface specification. In which
case, the appropriate interface within the object is used. This works as long as the
function names within the interfaces are unique.