CallWhen
A function added by the New Vegas Script Extender version 6.2.4.
Contents
Description
Executes a function when a specified condition function returns true exactly once. Condition is evaluated each frame until it becomes true.
Every queued call is removed when loading the game (GetGameLoaded), so they may need to be reset during then.
- NOTE: This means that callbacks created using this function are NOT savebaked, which could potentially cause bugs if a callback was expected to keep running after saving and reloading a save while the callback was running.
Runs in both GameMode and MenuMode, unless DontRunInMenuMode and/or DontRunInGameMode flags are enabled (see below). Will also run while paused (meaning while main menu / pause menu / console menu MenuModes are open) unless DontRunWhilePaused is enabled.
The following features have been added starting from xNVSE 6.2.6.
flags is a bitmask, whose bits toggle on/off the following features:
PassArgsToTheCalledFunction = 1 (bit #0) - xNVSE 6.2.6 PassArgsToTheConditionFunction = 2 (bit #1) - xNVSE 6.2.6 DontRunInMenuMode = 4 (bit #2) - xNVSE 6.2.8 DontRunInGameMode = 8 (bit #3) - xNVSE 6.2.8 DontRunWhilePaused = 16 (bit #4) - xNVSE 6.3.0
For example, if flags = 0, then none of these features are on. If flags = 0b11 (Binary Notation, or 3 in decimal), then the first two are on. By default, all flags are off (flags = 0).
Arguments can be passed like Call to the function. If an arg is an array, then its lifetime will be extended until the callbacks have stopped.
If PassArgsToTheCalledFunction is on, then the Call-like args will be passed to the udf, and if PassArgsToTheConditionFunction is on, they'll be passed to the condition UDF. Both flags can be on at the same time.
Syntax
reference.CallWhen udf:script condition:script flags:int{0} multi:arg(up to 15)
Example
CallWhen ({} => print "Alert! You're almost dying!") ({} => player.GetAV Health < 10)
When player health goes below 10, left function is called exactly once and never again (unless CallWhen is executed again later).