Difference between revisions of "Ar Construct"
Jump to navigation
Jump to search
Added some additional text from the OBSE doc
imported>CSbot (Automated import of articles) |
imported>QQuix (Added some additional text from the OBSE doc) |
||
Line 1: | Line 1: | ||
{{Function | {{Function | ||
| origin = OBSE | | origin = OBSE | ||
| summary = Creates a new array_var and assigns it to an array variable. Must be called within the context of an OBSE expression such as [[Let]]. The parameter specifies the type of array to create: | | summary = Creates a new array_var and assigns it to an array variable. Must be called within the context of an OBSE expression such as [[Let]]. The parameter specifies the type of array to create: Array, Map, or StringMap. | ||
| name = ar_Construct | | name = ar_Construct | ||
| returnVal = array_var | | returnVal = array_var | ||
Line 11: | Line 10: | ||
}} | }} | ||
}} | }} | ||
*Array: | |||
:An Array behaves like arrays in most programming languages: the key is an unsigned integer starting at zero, and there are no gaps between elements. (In other words, if an element exists at indexes 1 and 3 then an element necessarily exists at 0 and 2). Attempting to access an element using a key which is greater than the highest key in the array results in an error. The only exception to this rule is during assignment: it is okay to assign a value to the key which is one greater than the highest key in the array. | |||
*Map: | |||
:A Map associates numeric keys with values. Unlike an Array, a Map allows negative and floating point numbers to be used as keys and allows gaps to exist between elements. | |||
*StringMap: | |||
:Like a Map, except the keys are strings. Keys are case-insensitive, so ''array[INDEX]'' and ''array[index]'' both refer to the same value. There is no practical limit on the length of the strings used as keys. StringMaps can be used to simulate C-style structs by associating named properties with data values. | |||
==Notes== | |||
*An array_var must be initialized before it can be used in expressions, either by explicitly initializing it using ar_Construct, assigning the value of another array_var to it, or assigning it the return value of a command returning an array such as GetItems. | |||
*Most array operations should be performed within OBSE expressions such as Let or Eval statements. | |||
*Array elements cannot be passed directly to most commands as arguments. *Assigning one array to another as in Let array_1 := array_2 causes both array_1 and array_2 to refer to the same array, as illustrated below: | |||
array_var a | |||
array_var b | |||
let a := ar_Construct Array | |||
let a[0] := "First elem" | |||
let b := a ; b now refers to the same array as a | |||
let b[1] := "Second elem" ; array now contains two elements | |||
[[Category:Functions]] | [[Category:Functions]] |