Ar FindWhere

From GECK
Jump to: navigation, search


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

Description

Returns the value of the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, 0 is returned.

Syntax

[help]
(multi) Ar_FindWhere Source:array FindFunction:function/lambda 

Example

array_var aIter
array_var aNumbers = ar_List 5, 12, 8, 130, 44
int iResult = ar_FindWhere aNumbers ({aIter} => *aIter > 10);

Content of iResult: 12

Checking if no matches were found

If it's possible that no matches will be found, then a "not-found" result can be detected in the following way.
This assumes that the number 0 is NOT a valid value inside the array; if it is, then there is no way to discern if the search was successful or not.

ref rBaseActor = GSSunnySmiles
array_var aIter

array_var aResult = &(ar_FindWhere aDetectingActors ({aIter} => (*aIter).GBF == rBaseActor))
if eval ((TypeOf *aResult) != "Number" || (*aResult != 0))
     let ref rActorRef = *aResult
else
     ;* Couldn't find a detecting actor with that actor baseform.
endif

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 aNumbers. If aWords was a String Map then it would contain the string key.

See Also