Difference between revisions of "Array Variable"
no edit summary
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...") |
imported>Pintocat |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Template:Community_Wiki}} | |||
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 '<b>set .. to ..</b>', and [[Eval|if eval]] instead of simply '<b>if</b>'. | 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 '<b>set .. to ..</b>', and [[Eval|if eval]] instead of simply '<b>if</b>'. | ||
Line 15: | Line 19: | ||
==Simple Example== | ==Simple Example== | ||
Regular array, all keys are consecutive integers from 0: | |||
<pre> | <pre> | ||
array_var aBeatles | array_var aBeatles | ||
Line 27: | Line 32: | ||
endif | endif | ||
let aBeatles[1] := SunnyREF ; * | let aBeatles[1] := SunnyREF ; * change element 1 (second) to SunnyREF | ||
; aBeatles array now contains: JohnREF, SunnyREF, GeorgeREF, RingoREF | ; aBeatles array now contains: JohnREF, SunnyREF, GeorgeREF, RingoREF | ||
</pre> | </pre> | ||
== | Map array, keys may be any unique float: | ||
<pre> | |||
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" | |||
</pre> | |||
String map array, all keys are unique strings: | |||
<pre> | |||
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 | |||
</pre> | |||
==Array Functions== | |||
*Creation: [[Ar_Construct]], [[Ar_List]], [[Ar_Map]], [[Ar_Range]] | *Creation: [[Ar_Construct]], [[Ar_List]], [[Ar_Map]], [[Ar_Range]] | ||
*Modification: [[Ar_Append]], [[Ar_Insert]], [[Ar_InsertRange]], [[Ar_Resize]], [[Ar_Erase]] | *Modification: [[Ar_Append]], [[Ar_Insert]], [[Ar_InsertRange]], [[Ar_Resize]], [[Ar_Erase]] | ||
Line 43: | Line 74: | ||
*Searching: [[Ar_Find]], [[Ar_HasKey]], [[Ar_First]], [[Ar_Last]], [[Ar_Next]], [[Ar_Prev]], [[Ar_Keys]] | *Searching: [[Ar_Find]], [[Ar_HasKey]], [[Ar_First]], [[Ar_Last]], [[Ar_Next]], [[Ar_Prev]], [[Ar_Keys]] | ||
*Debugging: [[Ar_Dump]], [[Ar_DumpID]] | *Debugging: [[Ar_Dump]], [[Ar_DumpID]] | ||
==See Also== | |||
*[[Tutorial: Array Variables 1]] | |||
*[[Let]] | |||
*[[Eval]] | |||
*[[Foreach]] | |||
*[[Associating data with a reference]] | |||
[[Category:Array Variables]] | [[Category:Array Variables]] | ||
[[Category:NVSE]] | [[Category:NVSE]] |