Ar Filter

From GECK
Jump to: navigation, search


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

Description

Takes an array and a function and returns a new array that containing elements that pass the test implemented by the provided filter function.

Syntax

[help]
(array) Ar_Filter source:array filter:function/lambda 

Example

array_var aWords = ar_List "spray", "limit", "elite", "exuberant", "destruction", "present"

array_var aResult = ar_Filter aWords ({array_var aIter} => sv_Length (*aIter) > 6)

Content of aResult: "exuberant", "destruction", "present"

array_var aResult = ar_Filter aActors (begin function { array_var aIter }
    ref rActor = aIter["value"]
    if rActor.GetDead == 0
        SetFunctionValue 1
    endif
end)
; equivalent to ar_Filter aActors ({array_var aIter} => !(*aIter).GetDead)
; filters out all dead actors

Notes

  • To see why the * operator is used and why aIter is an array_var, see Dereference/Unbox in NVSE Expressions.
  • aIter["key"] will contain the index of aWords. If aWords was a String Map then it would contain the string key.

See Also