Keep Oninit() permanent active?

Post » Thu Jun 21, 2012 5:32 am

Any way to keep OnInit() permanent active? Usually it only executes once.
I want to modify actor values on each startup but I don't want them to go into saves, that means I have to run .setAV every time...
Or is there a better way to mod actor values directly in creation kit editor?

Sadly the OnLoad function is not for "on game load" :(
User avatar
Kari Depp
 
Posts: 3427
Joined: Wed Aug 23, 2006 3:19 pm

Post » Thu Jun 21, 2012 3:15 am

Well, you could put a loop in there...that would keep the code running until the object in question is deleted...

Bool Property Looping=False AutoEvent OnInit()   If !Looping	   Looping = True	   While Looping		  ; Do this forever, so long as we still exist	   endWhile   endIfEndEvent

You can stop it by setting Looping to false from outside.
User avatar
Joey Avelar
 
Posts: 3370
Joined: Sat Aug 11, 2007 11:11 am

Post » Wed Jun 20, 2012 2:12 pm

Hm that could work but isn't there anything better to just fire up once when skyrim saves load and then stops?
It should not depend on code from outside...
User avatar
Aliish Sheldonn
 
Posts: 3487
Joined: Fri Feb 16, 2007 3:19 am

Post » Wed Jun 20, 2012 7:54 pm

You could do the same thing, but use the OnCellLoad() event instead? Your question was how to keep OnInit "active" (I.E. running), however. By using the boolean, you can prevent it from running more than once. If that's your real goal (get one run when game starts, then not again)

To make it run once EVERY time the game loads, make a second boolean that is a normal variable and not a property (This will reset when the game is restarted) and use that to kill the old loop so the new loop can take over.
User avatar
Claudia Cook
 
Posts: 3450
Joined: Mon Oct 30, 2006 10:22 am

Post » Wed Jun 20, 2012 3:57 pm

OnCellLoad fires every time the player loads a cell. This is both every time they fire up a saved game, and everytime they enter a new cell (i.e. interior-> exterior).

OnInit will only fire when the script itself starts. Scripts can apparently be reset (especially if they don't have the "Run Once" flag active in a a quest they are attached too), but generally they only fire once.

The first one is likely what you want to be using.
User avatar
JAY
 
Posts: 3433
Joined: Fri Sep 14, 2007 6:17 am

Post » Thu Jun 21, 2012 12:18 am

fire up once when skyrim saves load and then stops?
It's a jury rig, but the below with a 'If GetGameLoaded(EmptyLVLI, ObscureForm, SomeContainer)' check will only return true once per save load, at least for now 'til we've OnGameLoaded()...
Bool Function GetGameLoaded(LeveledItem akLeveledItem = None, Form akForm = None, ObjectReference akContainer = None)	akContainer.AddItem(akLeveledItem, 1, True)	If akContainer.GetItemCount(akForm)		akContainer.RemoveItem(akForm, akContainer.GetItemCount(akForm), True)		Return False	Else		akLeveledItem.AddForm(akForm, 1, 1)		Return True	EndIfEndFunction 
User avatar
Sasha Brown
 
Posts: 3426
Joined: Sat Jan 20, 2007 4:46 pm

Post » Thu Jun 21, 2012 12:38 am

It's a jury rig, but the below with a 'If GetGameLoaded(EmptyLVLI, ObscureForm, SomeContainer)' check will only return true once per save load, at least for now 'til we've OnGameLoaded()...
Bool Function GetGameLoaded(LeveledItem akLeveledItem = None, Form akForm = None, ObjectReference akContainer = None)	akContainer.AddItem(akLeveledItem, 1, True)	If akContainer.GetItemCount(akForm)		akContainer.RemoveItem(akForm, akContainer.GetItemCount(akForm), True)		Return False	Else		akLeveledItem.AddForm(akForm, 1, 1)		Return True	EndIfEndFunction 
What exactly is adding akLevelledItem to the container doing? You don't seem to be checking for it anywhere...are you using that as a check somwehere outside the function to determine whether to call it in the first place?
User avatar
scorpion972
 
Posts: 3515
Joined: Fri Mar 16, 2007 11:20 am

Post » Wed Jun 20, 2012 5:04 pm

	If GetGameLoaded(EmptyLVLI, ObscureForm, SomeContainer)		; Do stuff once per save load		Debug.Notification("GetGameLoaded()")	Else		; Do other stuff		Debug.Notification("!GetGameLoaded()")	EndIf
The 'akLeveledItem.AddForm(akForm, 1, 1)' part doesn't get saved...
User avatar
Trevi
 
Posts: 3404
Joined: Fri Apr 06, 2007 8:26 pm

Post » Thu Jun 21, 2012 12:32 am

	If GetGameLoaded(EmptyLVLI, ObscureForm, SomeContainer)		; Do stuff once per save load		Debug.Notification("GetGameLoaded()")	Else		; Do other stuff		Debug.Notification("!GetGameLoaded()")	EndIf
The 'akLeveledItem.AddForm(akForm, 1, 1)' part doesn't get saved...

SO you're adding an object of some sort (doesn't say here what it is) to a levelled item inside the container, that is presumably not of the akForm type? Wouldn't it be easier to use a resetting boolean?


Put this function on a persistant object.

Bool Check = True{ According to Bethesda, This should reset on game load, but not at any other time if the object is persistant. }Bool Function GetGameLoaded()    if Check        Check = False        return True    else        return False    endifEndFunction
User avatar
Dominic Vaughan
 
Posts: 3531
Joined: Mon May 14, 2007 1:47 pm

Post » Wed Jun 20, 2012 6:21 pm

Works for the first save load, but not for consecutive loads.
User avatar
Beast Attire
 
Posts: 3456
Joined: Tue Oct 09, 2007 5:33 am

Post » Wed Jun 20, 2012 3:50 pm

wow, this seems to be more complitated as i thought. will try it tomorrow :wink:
hopefully SKSE editor support will come soon - bethesda gave us VERY limited functions, even missing the most basic stuff :(
User avatar
IM NOT EASY
 
Posts: 3419
Joined: Mon Aug 13, 2007 10:48 pm

Post » Thu Jun 21, 2012 5:02 am

the point is: this method is based on a bug. If bethesda fixes it, your script will not work after.
User avatar
stephanie eastwood
 
Posts: 3526
Joined: Thu Jun 08, 2006 1:25 pm

Post » Wed Jun 20, 2012 8:40 pm

SO you're adding an object of some sort (doesn't say here what it is) to a levelled item inside the container, that is presumably not of the akForm type? Wouldn't it be easier to use a resetting boolean?
The LVLI is empty other than the form added with AddForm(). Doesn't matter what the object is. The first time the function is called after any save load, it'll return true 'cause akForm isn't there. Each time thereafter until reload, it'll return false.
the point is: this method is based on a bug. If bethesda fixes it, your script will not work after.
Yup. Would be nice if we could just set a bGetGameLoaded "Constant" GLOB from 1 to 0 each save load, but none of the PapyrusGLOB functions will set a "Constant", unfortunately.
Bool Check = True{ According to Bethesda, This should reset on game load, but not at any other time if the object is persistant. }Bool Function GetGameLoaded()	if Check		Check = False		return True	else		return False	endifEndFunction
^Works for the first save load, but not for consecutive loads.

Edit: Wups. Meant to edit the previous post.
User avatar
Angela Woods
 
Posts: 3336
Joined: Fri Feb 09, 2007 2:15 pm


Return to V - Skyrim