How do I run a script on every load?

Post » Sat May 28, 2011 7:39 am

I need to initialize some non-persistent settings every time the game starts.

I set up an auto-start quest with a script that sets the settings then runs stopquest. But it only runs the first time, then is ignored because the save game has a record that the quest has already run.

I may be missing something, but is there a simple, reliable way to run a script every time the game starts?
User avatar
Mark
 
Posts: 3341
Joined: Wed May 23, 2007 11:59 am

Post » Sat May 28, 2011 10:35 am

There are two FOSE functions that may be relevant.

GetGameLoaded Description: returns 1 after a game is loaded on a per-script basis. For each script that calls GetGameLoaded, the command will return true exactly once each time the game is loaded and false thereafter. < this will run even when a save is loaded.

GetGameRestarted. Description: returns 1 when the game is restarted on a per-script basis. For each script that calls GetGameRestarted, the commands returns true exactly once per game session. Useful for situations in which a script must set certain object properties or settings each time the game is started.
User avatar
Siidney
 
Posts: 3378
Joined: Fri Mar 23, 2007 11:54 pm

Post » Sat May 28, 2011 7:10 am

Brilliant. GetGameRestarted is exactly what I need.
User avatar
N3T4
 
Posts: 3428
Joined: Wed Aug 08, 2007 8:36 pm

Post » Sat May 28, 2011 3:39 pm

I don't know if this will be of help, but if you don't want to use FOSE, perhaps a OnLoad begin block is what you need? Or is it a global variable in a quest?
User avatar
Chloe Botham
 
Posts: 3537
Joined: Wed Aug 30, 2006 12:11 am

Post » Sat May 28, 2011 3:39 pm

I don't know if this will be of help, but if you don't want to use FOSE, perhaps a OnLoad begin block is what you need? Or is it a global variable in a quest?
OnLoad is for when the model renders (even if disabled). Without FOSE, a script could be made to run all the way through and only once per save load using a "Constant" global set to 0 by default as a check.

scn RunOnceAfterLoadingSaveQuestSCPTBegin GameMode    If bDoOnceGLOB        Return ; Minimize resource consumption    Else        Set bDoOnceGLOB to 1        ;Do stuff    EndIfEnd
Since the "Constant" global's value won't persist in a save, it will revert to 0 and ensure everything happens, but only once per save load.

If you opt to go the FOSE route, I'd recommend GetGameLoaded rather than GetGameRestarted as you'll probably want your script to run after loading any given save to ensure things aren't botched by saved data if one loads multiple saves between game restarts.
User avatar
FLYBOYLEAK
 
Posts: 3440
Joined: Tue Oct 30, 2007 6:41 am

Post » Sat May 28, 2011 3:05 am

Interesting. I did not know that about globals.

Regarding my application, GetGameRestarted actually works better. I am using FOSE to add a setting to the users .ini file. I just need to add it once every time the game engine starts, since it is not information stored in the save. But thanks for the "gotcha" warning.
User avatar
James Wilson
 
Posts: 3457
Joined: Mon Nov 12, 2007 12:51 pm

Post » Sat May 28, 2011 4:13 am

Without FOSE, a script could be made to run all the way through and only once per save load using a "Constant" global set to 0 by default as a check.

Another use for constant globals - nice!
User avatar
scorpion972
 
Posts: 3515
Joined: Fri Mar 16, 2007 11:20 am

Post » Sat May 28, 2011 2:03 pm

Another use for constant globals - nice!
Vanilla's GetGameLoaded. The idea stemmed from your ideas pertaining to the FOSE global, so thanks for adding that tool to my toolbox as it's come in quite handy since. :)
User avatar
Trista Jim
 
Posts: 3308
Joined: Sat Aug 25, 2007 10:39 pm


Return to Fallout 3