Jump to content

Event OnInit() and Event OnUpdate()


marieruth

Recommended Posts

I've read on other sites that OnUpdate() has become the new "GameMode" of Papyrus scripting, but OnInit() could be used as the same. The thing that has confused me the most is when to use one or the other (or both).

 

Based on what I've seen on the Wiki, OnUpdate() is pretty useful when you have something that will update... Something like RegisterForUpdate(), but could also be used in its own block after an OnInit() block.

 

But if I make a script for a spell that is supposed to place an item in the world, I don't really know which one to use, since there is no update other than the object being placed in the world after the marker is placed in the world for the object to spawn to.

Link to comment
Share on other sites

I've read on other sites that OnUpdate() has become the new "GameMode" of Papyrus scripting, but OnInit() could be used as the same. The thing that has confused me the most is when to use one or the other (or both).

 

Based on what I've seen on the Wiki, OnUpdate() is pretty useful when you have something that will update... Something like RegisterForUpdate(), but could also be used in its own block after an OnInit() block.

 

But if I make a script for a spell that is supposed to place an item in the world, I don't really know which one to use, since there is no update other than the object being placed in the world after the marker is placed in the world for the object to spawn to.

RegisterForSingleUpdate (always use single) can be used to call an event in a certain time frame.

 

i.e.

Event OnInit(); when this script is initialized
     RegisterForSingleUpdate(5.0);register for an onupdate event in 5 seconds
EndEvent

Event OnUpdate()
     ;do things
EndEvent
Link to comment
Share on other sites

 

I've read on other sites that OnUpdate() has become the new "GameMode" of Papyrus scripting, but OnInit() could be used as the same. The thing that has confused me the most is when to use one or the other (or both).

 

Based on what I've seen on the Wiki, OnUpdate() is pretty useful when you have something that will update... Something like RegisterForUpdate(), but could also be used in its own block after an OnInit() block.

 

But if I make a script for a spell that is supposed to place an item in the world, I don't really know which one to use, since there is no update other than the object being placed in the world after the marker is placed in the world for the object to spawn to.

RegisterForSingleUpdate (always use single) can be used to call an event in a certain time frame.

 

i.e.

Event OnInit(); when this script is initialized
     RegisterForSingleUpdate(5.0);register for an onupdate event in 5 seconds
EndEvent

Event OnUpdate()
     ;do things
EndEvent

 

 

Okay that seems much clearer to me, thank you. Why only use RegisterForSingleUpdate(), by the way?

Link to comment
Share on other sites

Single updates will halt after the update event has ran. Unless a new single update is registered. This is preferred should a mod be uninstalled while the update is waiting to take place. The save game retains knowledge of the uninstalled mod and prints an error to the log when the update time runs out. That is it, it is done.

 

With the continuous update it never stops unless it is unregistered. If the user uninstalls the mod before it gets a chance to be unregistered, the save game using its retained knowledge print out an error when the update time runs out. And it will keep doing so because it has never been unregistered.

 

Now it is less of a worry since SKSE has implemented the ClearInvalidRegistrations entry in its INI file. Yet, it doesn't catch everything nor does everyone use SKSE.

 

TL;DR

The single variant is more thread safe & offers less CTD potential

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...