Difference between revisions of "Papyrus FAQs"

2,465 bytes added ,  12:19, 11 May 2016
imported>Digitalparanoid
imported>Digitalparanoid
Line 231: Line 231:


=== How do I write save-safe scripts then? ===
=== How do I write save-safe scripts then? ===
According to SmkViper:
<pre>
Removing mods and continuing with a save that relies on that mod is not and
never has been supported. Proceed at your own risk. Demons may fly out of your
monitor and spray you with silly string. (You think I'm kidding - have you heard
of Bob the modder? No? Exactly.)
</pre>
However, here are some evolving guidelines that can be followed to reduce the incidence of uninstallation issues and/or shift the blame to user error:
# Instead of using a <code>While</code> loop, use an <code>OnTimer()</code> event. The <code>OnTimer()</code> event is Fallout 4's version of Skyrim's <code>OnUpdate()</code>. Refer to the question and answer below for more information.
# Avoid endless <code>While</code> loops that cannot terminate after the plugin has been removed. For example, a <code>While Player.HasPerk(kPerk)</code> loop can terminate if <code>kPerk</code> references a perk unique to the plugin. Removing the plugin removes the perk, and so when the player loads a save, the thread can then exit. However, if <code>kPerk</code> references a vanilla perk, <code>HasPerk()</code> will always evaluate to <code>True</code> and the <code>While</code> loop will continue iterating over instructions that may require objects which no longer exist, and therefore keep the thread alive, consuming memory, contributing to script lag, and producing errors. Refer to the above question for more information about how <code>While</code> loops and saves interact.
# Always finish your code as fast as possible. This ultimately means making optimizations to both your scripts and your systems. For example, if you need a <code>While</code> loop to iterate through a large formlist or array, chunk the formlist or array, and in between each chunk, give the loop an opportunity to exit. You might also want to ensure that there are enough conditions in place that your script can run only when needed, do its job, and get out when the job's done.
# Provide the user with the ability to "uninstall" your mod while in the game. This can be done by offering users a "Shutdown" option in a holotape menu that forcibly exits all continuously running scripts. Some users may not take the time to take advantage of this feature, so it remains important to ensure that you've taken the necessary steps to write save-safe scripts.
# Finally, warn users that uninstalling mods and continuing with saves that rely on those mods is unsupported and unsafe.
=== How would I emulate a Break statement in a While loop? ===
=== How would I emulate a Break statement in a While loop? ===
=== Are scripts saved in save games? ===
=== Are scripts saved in save games? ===