Ar Generate

From GECK
Jump to: navigation, search


A function added by the New Vegas Script Extender version 6.1.7.

Description

Creates a new Array populated with a specified amount of elements.

For each element, starting from the first element to the last one, valueGenerator is called and an element is set to that result.

If keyGenerator is omitted, then the resulting array will be of Array type, and each value being generated is being appended to that array.
Otherwise, each Value being generated is tied to the Key generated by keyGenerator.

In the latter case, the type of the returned array will be a StringMap / Map, depending on the type of value that the keyGenerator first returns.
Key generation and Value generation are evaluated side-by-side, with the valueGenerator function being called first.

Returns Ar_Null if the keyGenerator function ever returns a non-string or non-numeric element.

Syntax

[help]
(array) Ar_Generate numElems:int valueGenerator:function/lambda
  keyGenerator:function/lambda

Example

let array_var aTest := ar_Generate 5 ({} => 0)

aTest is filled with 5 elements, which are each initialized to 0.

  • Note that this is less efficient than `ar_Init 5 0`, as the result has to be re-evaluated for each element, even though it will always be zero.
let array_var aNumbers := ar_Generate 13 ({} => (Rand 0, 100))

aNumbers is filled with 13 elements, which are each assigned a random float number between 0 and 99.

let int iCounter := -1
let array_var aArray := Ar_Generate 20, ({} => (player.GetEquippedObject (iCounter += 1))) 

aArray is filled with forms; from index 0 to 19, the array's elements are set to the equipped object (if any) occupying the equip slot determined by that index.

  • Note that an object can occupy multiple equip slots, so this method is not preferable to retrieve each unique equipped form. Use GetEquippedItems for that instead.
scn DumpLimbHealthUDF

begin Function { }

    let ref rActor := this
    let int iCounter := 24
    let array_var aLimbHealths := ar_Generate 7 ({} => rActor.GetAV (iCounter += 1)) ({} => ActorValueToStringC iCounter)
    ar_dump aLimbHealths 

end

This function dumps the health of each limb for the calling actor.
It does this by generating a StringMap by calling Ar_Generate, which loops through each AV code for limb health (25-31) and calling some functions on those limb IDs.

Example output:

** Dumping Array #1 **
Refs: 1 Owner 0F: Some Mod.esp
[ BrainCondition ] : 100.000000
[ EnduranceCondition ] : 54.111355
[ LeftAttackCondition ] : 0.000000
[ LeftMobilityCondition ] : 0.000000
[ PerceptionCondition ] : 100.000000
[ RightAttackCondition ] : 100.000000
[ RightMobilityCondition ] : 100.000000

Notes

  • The keyGenerator argument was only added in xNVSE v6.2.1.

See Also