Difference between revisions of "Ar HasKey"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Syscrusher
(Added an example of a nontraditional use of this function; I have tested code like this in my mod.)
imported>Syscrusher
(Backed out my earlier hint -- further testing found an exception :-()
 
Line 14: Line 14:
   }}
   }}
}}
}}
This function can also be used to detect a new game load (after a restart, or loading from a save), in a way that avoids some of the limitations of [[GetGameRestarted]], [[GetGameLoaded]], and [[OnLoad]] blocks. The first two of these only return true for the first invocation of each from a particular script, regardless of how many base objects and references use that script. The OnLoad block may not execute if the player starts up the game and immediately loads a save from the same cell as the object.


Code like the following can be used to work around this, exploiting the otherwise-inconvenient fact that OBSE arrays are not persistent across game loads:
Array_var initFlagArray
Begin GameMode
    if Ar_HasKey initFlagArray, 0
      ; Initialization has been completed.
    else
      ; Need to initialize. Start by clearing the condition.
      let initFlagArray := Ar_construct Array
      let initFlagArray[0] := 0  ; Value does not matter as long as it exists
    endif
    ...
End


[[Category:Functions]]
[[Category:Functions]]

Latest revision as of 00:10, 27 September 2014

< [[::Category:Functions|Category:Functions]]

A function added by the Oblivion Script Extender.

Syntax:

(hasKey:bool) ar_HasKey src:array key:arrayKey

Returns true if the array has an element with the specified key.