Difference between revisions of "Ar HasKey"

1,006 bytes added ,  20:39, 26 September 2014
Added an example of a nontraditional use of this function; I have tested code like this in my mod.
imported>QQuix
(Organizing the Array Functions category list)
imported>Syscrusher
(Added an example of a nontraditional use of this function; I have tested code like this in my mod.)
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]]
Anonymous user