Ar HasKey

From GECK
Jump to: navigation, search


A function added by the New Vegas Script Extender.

Description

Returns True (1) if the specified array contains the specified key, or otherwise False (0).

Syntax

[help]
(bool) Ar_HasKey ToCheck:array Key:arraykey 

Example

if eval Ar_HasKey SomeArray, SomeKey
   ; SomeArray has SomeKey
endif

Examples With Extraneous Context

array_var aMagicNumberToString
string_var slot

let aMagicNumberToString := Ar_Map 2::"Upper Body", 5::"Weapon"

if eval Ar_HasKey aMagicNumberToString, 2
    ; True, the array has the key: 2
    let slot := aMagicNumberToString[2] ; I know this is safe
endif

if eval Ar_HasKey aMagicNumberToString, 5
    ; True, the array has the key: 5
endif

if eval Ar_HasKey aMagicNumberToString, 13
    ; False, the array has no key: 13 (or any except 2 and 5 in this case)
endif

Exactly the same with a "stringmap"

array_var aStringToMagicNumber
int iMN

let aStringToMagicNumber := Ar_Map "Upper Body"::2, "Weapon"::5

if eval Ar_HasKey aStringToMagicNumber, "Upper Body"
    ; True, the array has the key: "Upper Body"
    let iMN := aStringToMagicNumber["Upper Body"] ; I know this is safe
endif

if eval Ar_HasKey aStringToMagicNumber, "Weapon"
    ; True, the array has the key: "Weapon"
endif

if eval Ar_HasKey aStringToMagicNumber, "Another"
    ; False, the array has no key: "Another" (or any except previous two)
endif

Notes

  • It will work with any type of array, although it is most appropriate for "map" and "stringmap" types, since with the regular "array" type (Ar_List) the keys are always consecutive from 0, so you could simply use Ar_Size instead.

See Also