What would cause a run-once script to repeatedly fire?

Post » Mon Nov 19, 2012 9:42 am

In a mod that I made, I use a quest with a script to set up the initial placement of certain items. This is what it looks like, in broad strokes:

scriptname InitialSetupQuestScript extends Questquest property initialSetupQuest Autoevent OnInit()   RegisterForSingleUpdate(30)endEventevent onUpdate()<<>>Debug.MessageBox ("Items have been placed!")initialSetupQuest.Stop()endEvent

I myself do NOT have this issue, and most users don't either. However, SOME users reported that the script runs again and again, and the message box pops up endlessly until the user quits the game. Stopping the quest via console (stopQuest initialSetupQuest) does not make the box go away, it keeps popping up every second (on every update it seems).

Why would this happen? I explicitly register for a single update at 30 seconds after load, and then stop the quest once the update happens.
User avatar
Ria dell
 
Posts: 3430
Joined: Sun Jun 25, 2006 4:03 pm

Post » Mon Nov 19, 2012 9:56 am

Try:
Spoiler
ScriptName InitialSetupQuestScript Extends Quest ; "Start Game Enabled" / "Run Once"Event OnInit()	Utility.Wait(30.0) ; Use a float rather than an int to avoid unnecessary autocasting	; Place items	Debug.MessageBox("Items have been placed!")	Stop() ; You do not need the quest property as functions can be called implicitlyEndEvent
Provided the "Run Once" flag is ticked and nothing else is starting the quest externally, all should happen only once.
User avatar
Antonio Gigliotta
 
Posts: 3439
Joined: Fri Jul 06, 2007 1:39 pm

Post » Mon Nov 19, 2012 12:44 pm

Justin,

Isn't there an issue with onInit that causes it to fire twice?
User avatar
Rex Help
 
Posts: 3380
Joined: Mon Jun 18, 2007 6:52 pm

Post » Mon Nov 19, 2012 9:41 am

Only if the "http://www.creationkit.com/Quest_Data_Tab" flag isn't ticked.


OnInit is run when an object first becomes scripted and will run whenever an object is reset (since a reset clears all your properties and variables back to their initial values).

So what you’re seeing is the quest being created and the script attached running OnInit, then the game starting up the quest (since it starts enabled), which, because the quest can run more than once, will reset the script and re-run the OnInit event.
User avatar
JaNnatul Naimah
 
Posts: 3455
Joined: Fri Jun 23, 2006 8:33 am


Return to V - Skyrim