Category:Auxiliary-Timer Functions (SO)

From GECK
Jump to: navigation, search

The Auxiliary-Timers interface is a utility added by the ShowOff NVSE Plugin in Fallout: New Vegas, and is an alternative method for dynamically storing and managing timers that automatically count down, unless paused. Auxiliary-Timers (abbreviated as AuxTimers) are created, accessed, modified and deleted using a set of script commands.

AuxTimers are a specialized form of Auxiliary-Variables and share much of the same syntax.

Specifically, this interface serves as a replacement for writing timers inside scripts and manually counting them down using GetSecondsPassed. Since AuxTimers can be savebaked depending on the duration chosen for it, they typically serve as savebaked script callbacks. In comparison, callbacks like CallAfterSeconds are NOT savebaked.

Properties

  • An AuxTimer is defined by a Name (string, case-insensitive) and an Object (object reference/base form) that "owns" it. This Object:Name pair must, therefore, be unique. Note that different Objects may "own" a timer with the same Name and still count as a unique pair. Any Object may "own" any number of timers.
  • AuxTimers store a timer value that gets counted down and flags for how the timer should behave.

Duration & Accessibility

Duration:

An AuxTimer's duration setting determines its "life-span", i.e. whether it is permanent or temporary. Permanent AuxTimers are saved with the game. In contrast, temporary AuxTimers are not saved with the game. Instead, they are persistent for the duration of the current game session (much like global variables) but are discarded when the game is exited. Consider using file functions such as SetINIFloat to save information across multiple sessions.

Accessibility:

The accessibility setting determines which mods can "see" and manipulate the AuxTimer. A private AuxTimer is "private" to the mod it was created by, and can only be accessed/modified by scripts originating in that mod. This allows different mods to use the same timer names, associated with the same objects, without overwriting each other. A public AuxTimer, on the other hand, can be accessed/modified by any mod. This is an effective method for inter-mod communication and exchange of timer data, without any master-dependencies.


Enabling each property is done by adding a special prefix to the AuxTimer's name. The two properties, and their combinations, define four classes of AuxTimer, as summarized in the following table:

Class Prefix Example Saved w/ Game Persistent

in Session

Accessible By
Temporary-Public *_ "*_TimerName" No Yes Any mod
Permanent-Public _ "_TimerName" Yes No Any mod
Temporary-Private * "*TimerName" No Yes Creating mod
Permanent-Private None "TimerName" Yes No Creating mod

Examples

Here we have a UDF script that will act as an event handler for SetOnTimerStopHandler:

scn TestAuxTimerCallback

string_var sTimerName
ref rOwnerForm

begin Function { sTimerName, rOwnerForm }
	print "TestAuxTimerCallback >> RAN!"
	printvar sTimerName
	printvar rOwnerForm 
end

Its purpose will be to automatically run whenever our timer has counted all the way down and is stopped.
In order to register this event handler, we can use the following line:

SunnyREF.SetOnTimerStopHandler TestAuxTimerCallback "Test"

For this example, we chose "Test" as our AuxTimer's name, and SunnyRef as an arbitrary form to associate the timer with.

Note that event handlers registered with SetOnTimerStopHandler get cleared automatically when a save is loaded, so if the handlers are being registered in a quest script, calling SetOnTimerStopHandler every time GetGameLoaded returns true is recommended.

Finally, to start and create our AuxTimer, we can use AuxTimerStart:

SunnyRef.AuxTimerStart "Test" 5

This will create a private-permanent AuxTimer named "Test" belonging to SunnyRef that will count down for 5 seconds before stopping. It will count down in both GameMode and MenuMode by default, unless with specify other flags (see AuxTimerStart's page).

When the time has fully passed, the TestAuxTimerCallback event handler will automatically be called, allowing us to react to the timer being stopped.

And with that, our goal of setting up a save-baked callback is done!

See Also