Player APIs (BrightScript & Ja...
...
Object Reference
BrightScript Core Objects

roAssociativeArray

13min
this object allows you to store objects in an associative array (also known as a map, dictionary, or hash table), a data structure that associates objects with string keys using nested for each loops to iterate over the same roassociativearray instance can lead to unexpected behavior see the program statements docid\ xjncz5p2xsv5j9geofi13 for more details the roassociativearray object is created with no parameters createobject("roassociativearray") alternatively, an associative array can be created using brackets aa1 = {} aa2 = {key1 "value", key2 55, key3 5+3 } ifenum reset() as void resets the position to the first element of enumeration next() as dynamic returns a typed value at the current position and increments the position isnext() as boolean returns true if there is a next element isempty() as boolean returns true if the associative array contains no elements ifassociativearray addreplace(key as string, value as object) as void adds a new entry to the associative array, associating the supplied object with the supplied key string only one object may be associated with a key, so any existing object linked to that key is discarded this method is always case sensitive when creating keys, whereas object literal syntax (e g aa={bright "sign"} ) is case insensitive when creating keys unless setmodecasesensitive() is called lookup(key as string) as dynamic looks up the specified key and returns the associated object if there is no object associated with the key string, then this method will return invalid in many cases, the operators docid\ pl6ydtpgctydca5q2bw45 can be used as shorthand for the lookup() and addreplace() methods when working with associative arrays doesexist(key as string) as boolean looks up the specified key in the associative array if the key exists, true is returned; otherwise, false is returned delete(key as string) as boolean looks for an object in the associative array linked to the specified key if there is such an object, it is deleted and true is returned; otherwise, false is returned clear() as void removes all objects from the associative array setmodecasesensitive() as void makes all subsequent actions case sensitive all lookups and created keys (with the exception of the addreplace() method) are case insensitive by default lookupci(key as string) as dynamic looks for an object in the array associated with the specified key this method functions similarly to lookup() , with the exception that key comparisons are always case insensitive, regardless of case mode append(aa as roassociativearray) as void appends a second associative array to the first examples aa = createobject("roassociativearray") aa addreplace("bright", "sign") aa addreplace("tmol", 42) print aa lookup("tmol") print aa lookup("bright") the above script returns the following 42 sign alternatively, you can use the operators docid\ pl6ydtpgctydca5q2bw45 in place of the addreplace() and lookup() methods aa = {} aa bright = "sign" aa tmol = 42 print aa tmol print aa bright you can also specify an associative array as a multiline object literal aa = { bright "sign", tmol 42, pie 3 14 }