Difference between revisions of "Ar HasKey"
Jump to navigation
Jump to search
imported>Odessa (created) |
imported>Odessa (clarified examples) |
||
Line 11: | Line 11: | ||
|Type = arraykey}}}} | |Type = arraykey}}}} | ||
==Example== | ==Example== | ||
<pre> | |||
if eval Ar_HasKey SomeArray, SomeKey | |||
; SomeArray has SomeKey | |||
endif | |||
</pre> | |||
==Examples With Extraneous Context== | |||
<pre> | <pre> | ||
array_var aMagicNumberToString | array_var aMagicNumberToString |
Latest revision as of 19:04, 28 June 2014
< [[::Category:Functions|Category:Functions]]
A function added by the New Vegas Script Extender.
Description
Added by NVSE V4. Returns True (1) if the specified array contains the specified key, or otherwise False (0).
Syntax
(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.