Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Table of Contents

CreateObject(classname as String, [optional parameters]) as Object

Creates a BrightScript Component of class classname specified. Return invalid if the object creation fails. Some Objects have optional parameters in their constructor that are passed after name.


Type(variable, [optional version]) as String

Returns the type of a variable and/or object. See the BrightScript Component specification for a list of types.


GetGlobalAA() as Object

Each script has a global Associative Array. It can be fetched with this function. 
New in BrightScript 3.

Box(x as Dynamic) as Object

Box() will return an object version of an intrinsic type, or pass through an object if given one.

 bo = box("string")
bo = box(bo) ' no change to bo

Run(filename as String [ , Args…]) As dynamic

Run(filenamearray as Object [ , 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. 
If a filename string is passed, that file compiled and run. 
If an array of files are passed instead of a single filename, then each file is compiled and they are linked together, than run.


Eval(code as String) as Dynamic

Eval can be used to run a code snippet in the context of the current function. It performs a compile, and then the bytecode execution.

If a compilation error occurs, no byte execution is performed, and Eval returns an roList with one or more compile errors. Each list entry is an roAssociativeArray with ERRNO and ERRSTR keys describing the error.

If compilation succeeds, bytecode execution is performed and the integer runtime error code is returned. These are the same error codes as returned by GetLastRunRuntimeError().

Eval() can be usefully in two cases. The first is when you need to dynamically generate code at runtime.

The other is if you need to execute a statement that could result in a runtime error, but you don't want code execution to stop. 


    Print Eval("n=1/0") 



(Note that 20 = &h14 = ERR_DIV_ZERO = Divide by Zero error).

Do not use Eval() after calling CeateScene as it can cause unexpected bugs and crashes. Use roXMLElement.parse() or parseJSON() instead when initializing data. You can also use a downloadable component library to get the dynamic code. 

GetLastRunCompileError() as Object

Returns an roList of compile errors, or invalid if no errors. Each list entry is an roAssociativeArray with the keys: ERRNO, ERRSTR, FILESPEC, and LINENO.

GetLastRunRuntimeError() as Integer

Returns an error code result after the last script Run(). 
These two are normal:

Example: Assign variables to common runtime errors
  • No labels