Array Variable

Revision as of 08:47, 9 July 2014 by imported>Odessa (Created page with "Array variables are added by NVSE 4. Arrays are similar to form lists but allow for far more powerful capabilities with much easier scripting. Arrays are simple to use, provid...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Array variables are added by NVSE 4. Arrays are similar to form lists but allow for far more powerful capabilities with much easier scripting. Arrays are simple to use, provided you switch to using Let instead of the vanilla 'set .. to ..', and if eval instead of simply 'if'.

A tutorial on array variables is available.

Arrays Compared to Form Lists

  • Arrays may store any data type in any combination, form lists only base forms or references.
  • Form lists must be created in the GECK, arrays are created dynamically within scripts by letting a variable to a wide range of function that return different types of array.
  • Regular arrays (array lists) are organized identically to form lists, the first item is always at index 0, and the last at (total size - 1).
  • Map and String map arrays allow organization by user specified keys for each item.
  • Arrays may be easily looped through using Foreach
  • Both arrays and form lists can be searched using various functions.
  • Form lists require complicated scripting to sort or copy. Arrays may be easily copied and sorted using a single function from a range of possiblities.
  • Entries in a form list must be assigned to a variable via a function before they can be manipulated. Within NVSE expressions, or if using the Script Compiler Override, array entries may be manipulated directly using square brackets.
  • Arrays contents can be printed to the console with a single function for easy debugging, either from within a script or from the in game console.

Simple Example

array_var aBeatles
ref rActor

let aBeatles := Ar_List JohnREF, PaulREF, GeorgeREF, RingoREF

let rActor := aBeatles[0] ; * rActor == JohnREF

if eval aBeatles[2] == GeorgeREF
   ; element 2 (third) is GeorgeREF
endif

let aBeatles[1] := SunnyREF ; * set element 1 (second) to SunnyREF

; aBeatles array now contains: JohnREF, SunnyREF, GeorgeREF, RingoREF

See Also