Player APIs (BrightScript & Ja...
...
BrightScript
Language Reference

Operators

10min
operations in the innermost level of parentheses are performed first evaluation then proceeds according to the precedence in the following table operations on the same precedence are left associative, except for exponentiation, which is right associative description symbol(s) function calls or parentheses () array operators , \[] exponentiation ^ negation –, + multiplication, division, modulus , /, mod addition, subtraction +, comparison <, >, = , <>, <=, >= logical negation not logical conjunction and logical or or string operators the following operators work with strings <, >, =, <>, <=, >=, + function references the = and <> operators work on variables that contain function references and function literals logical and bitwise operators the and , or , and not operators are used for logical (boolean) comparisons if the arguments for these operators are boolean a = 20 b = 20 c = 20 if a = c and not(b > 40) then print "success" on the other hand, if the arguments for these operators are numeric, they will perform bitwise operations x = 1 and 2 ' x is zero y = true and false ' y is false when the and or or operator is used for a logical operation, only the necessary amount of the expression is executed for example, the first statement below will print "true", while the second statement will cause a runtime error (because "invalid" is not a valid operand for or ) print true or invalid print false or invalid dot operator the " " dot operator can be used on any brightscript object it also has special meaning when used on an roassociativearray object, as well as roxmlelement and roxmllist objects when used on a brightscript object, it refers to an interface or method associated with that object in the following example, ifint refers to the interface and setint() refers to a method that is part of that interface i = createobject("roint") i ifint setint(5) i setint(5) every object method is part of an interface however, specifying the interface with the " " dot operator is optional if the interface is omitted, as in the third line of the above example, each interface that is part of the object will be searched for the specified member if there is a naming conflict (i e a method with the same name appears in two interfaces), then the interface should be specified associative arrays when the " " dot operator is used on an associative array, it is the same as calling the lookup() or addreplace() methods, which are member functions of the docid\ sb0om1y oqlapfqnfs0xy object aa = {} aa newkey = "the value" print aa newkey note that the parameters of the " " dot operator are set at compile time; unlike the lookup() and addreplace() methods, they are not dynamic the " " dot operator is always case insensitive for example, the statement aa newkey=55 will create the entry "newkey" in the associative array to generate case sensitive keys, instantiate an roassociativearray object and use the setmodecasesensitive() method array and function call operators the \[ ] operator is used to access an array (i e any brightscript object that has an ifarray interface, such as roarray and rolist objects) it can also be used to access an associative array the \[ ] operator takes expressions that are evaluated at runtime, while the " " dot operator takes identifiers at compile time the ( ) operator can be used to call a function when used on a function literal (or variable containing a function reference), that function will be called the following code snippet demonstrates the use of both array and function call operators aa = createobject("roassociativearray") aa\["newkey"] = "the value" print aa\["newkey"] array = createobject("roarray", 10, true) array\[2] = "two" print array\[2] fivevar = five print fivevar() array\[1] = fivevar print array\[1]\() ' print 5 function five() as integer return 5 end function array dimensions arrays in brightscript are one dimensional multi dimensional arrays are implemented as arrays of arrays the \[ ] operator will automatically map multi dimensionality for example, the following two fetching expressions are the same dim array\[5,5,5] item = array\[1]\[2]\[3] item = array\[1,2,3] if a multi dimensional array grows beyond its hint size, the new entries are not automatically set to roarray equals operator the = operator is used for both assignment and comparison a = 5 if a = 5 then print "a is 5" unlike the c language, brightscript does not support use of the = assignment operator inside an expression this is meant to eliminate a common class of bugs caused by confusion between assignment and comparison when assignment occurs, intrinsic types are copied, while brightscript objects are reference counted