Array Variable

From the Fallout3 GECK Wiki
Jump to navigation Jump to search


Please Note: The official wiki is no longer being maintained by the community[edit | edit source]

The modding community for Fallout 3 and Fallout New Vegas has created its own wiki due to onerous and painful captcha requirements for every edit.

The active wiki contributors have moved to the new wiki -- for the most current information, visit:

http://geckwiki.com[edit | edit source]

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[edit | edit source]

  • 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[edit | edit source]

Regular array, all keys are consecutive integers from 0:

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 ; * change element 1 (second) to SunnyREF

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

Map array, keys may be any unique float:

array_var MagicNumberToString
string_var my_string

let MagicNumberToString := Ar_Construct "map"

let MagicNumberToString[2] := "Upper body"
let MagicNumberToString[5] := "Weapon"

; MagicNumberToString contains: 2::"Upper body", 5::"Weapon"

let my_string := MagicNumberToString[5] ; * my_string == "Weapon"

String map array, all keys are unique strings:

array_var StringToMagicNumber
int MyInt

let StringToMagicNumber := Ar_Construct "stringmap"

let StringToMagicNumber["Upper body"] := 2
let StringToMagicNumber["Weapon"] := 5

; StringToMagicNumber contains: "Upper body"::2, "Weapon"::5

let MyInt := StringToMagicNumber["Weapon"] ; * MyInt == 5

Array Functions[edit | edit source]

See Also[edit | edit source]