Does OnInit () in Quest Script fire twice?

Post » Wed Jun 20, 2012 12:05 am

Does OnInit () in Quest Script fire twice?

Here's a log of new installed mod - Inventory is a backpack:

Spoiler

First OnInit () from Inventory is a backpack (kuIIABQS) mod:
[03/12/2012 - 08:07:52PM] !kuIIABQS.OnInit

My other mods were activated in a previous game and so only get "game loaded". They do not fire their OnInit ().
Inventory and weight (kuIAWQS) has a new version and so a reset is detected:
[03/12/2012 - 08:07:52PM] !kuGAQS.OnItemAdded [MiscObject < (0A0012C7)>], 1, [ObjectReference < (FF000C8F)>], None[03/12/2012 - 08:07:52PM] !kuiawqs.initGameLoaded reset[03/12/2012 - 08:07:52PM] !kuEASQSMain.initGameLoaded loaded[03/12/2012 - 08:07:52PM] !kuAFTPVQS.initGameLoaded loaded[03/12/2012 - 08:07:52PM] !kuELAAWQS2.initGameLoaded loaded

Then kuIIABQS executes again:
[03/12/2012 - 08:07:52PM] !kuIIABQS.OnInit

The rest continues to "game load".
[03/12/2012 - 08:07:52PM] !kuCMQS.initGameLoaded loaded[03/12/2012 - 08:07:52PM] !kuGAQS.initGameLoaded loaded[03/12/2012 - 08:07:52PM] !kuASATQS.initGameLoaded loaded[03/12/2012 - 08:07:53PM] !kuBFAIQS.initGameLoaded loaded

kuIIABQS first-ever initialisation:
[03/12/2012 - 08:07:53PM] !kuIIABQS.initGameLoaded init

The rest continues to "game load". kuIAWQS fires OnInit () and runs its initialisation due to the reset.
[03/12/2012 - 08:07:53PM] !kuIIABQS.initGameLoaded loaded[03/12/2012 - 08:07:53PM] !kuiawqs.OnInit[03/12/2012 - 08:07:54PM] !kuiawqs.initGameLoaded init

Does this happen to you guys? I tested it in a blank mod and it does happen.
This simple Quest Script logs two OnInit ():
Scriptname kuTestOnInitQS extends Quest  Event OnInit ()	Debug.Trace ("kuTestOnInitQS OnInit")EndEvent

More than one Quest objects may be created on the player with this problem.
This is the case with my mod - even if I add a GetItemCount () == 0 conditional.
The 2nd OnInit () executes before the player gets the Quest object form the 1st OnInit ().
User avatar
Jonathan Montero
 
Posts: 3487
Joined: Tue Aug 14, 2007 3:22 am

Post » Wed Jun 20, 2012 11:47 am

Those findings do seem to confirm that written on the http://www.creationkit.com/OnInitpage.

Unless that event is causing a change outside of your quest then you can probably ignore it.
The Properties will hold their default values before the second call.
User avatar
Eire Charlotta
 
Posts: 3394
Joined: Thu Nov 09, 2006 6:00 pm

Post » Tue Jun 19, 2012 9:35 pm

Ahhh...yes. Thanks! I see it now:
If a Quest is set to run on game startup and doesn't have the "Run Once" flag ticked, its OnInit event will fire twice when it starts. Ticking the "Run Once" flag, however, prevents the Quest from being reset when it starts, so in this case its OnInit event will only fire once.

I'll need to add a variable check there so that it doesn't call functions twice.
User avatar
Klaire
 
Posts: 3405
Joined: Wed Sep 27, 2006 7:56 am

Post » Wed Jun 20, 2012 1:38 am

A variable check wouldn't be an appropriate way, as http://www.creationkit.com/OnInit is called when the script is first attached to the object, and whenever the object is reset. In both of these cases, all variable and property values are also reset.

Ideally, OnInit events should really only be used for initialisation, like non-literal variable initialisation or registering for updates.

Cipscis
User avatar
alyssa ALYSSA
 
Posts: 3382
Joined: Mon Sep 25, 2006 8:36 pm


Return to V - Skyrim