Operator – BrightSign BrightScript 2 Reference Guide User Manual
Page 13
![background image](https://www.manualsdir.com/files/776464/content/doc013.png)
13
Examples:
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
The “[ ]” operator takes expressions that are evaluated at runtime and so is different that a
“.” Operator in this way. The dot operator takes compile time identifiers.
Arrays in BrightScript are one dimension. Multi-dimension arrays are implemented as
arrays of arrays. The “[ ]” operator will automatically map “multi-dimensionality”. IE,
the following two expressions to fetch “item” are the same:
dim array[5,5,5]
item = array[1][2][3]
item = array[1,2,3]
(**NOTE: if a multi-dimension array grows beyond its hint size the new entries are not
automatically set to roArray**)
= Operator
“=” is used for both assignment and comparison. Example:
a=5
If a=5 then print “a is 5”
BrightScript does not support the use of the “=”Assignment operator inside an expression
(like C does). This is to eliminate the common class of bugs where a programmer meant
“comparison”, not “assignment”.
When an assignment occurs, intrinsic types are copied, but Roku Objects are reference
counted.