Difference between revisions of "Papyrus FAQs"

Jump to navigation Jump to search
1,593 bytes added ,  12:13, 11 May 2016
imported>Digitalparanoid
imported>Digitalparanoid
Line 198: Line 198:


=== Are While loops safe to use for persistent or continuous effects? ===
=== Are While loops safe to use for persistent or continuous effects? ===
According to SmkViper:
<pre>
Saves operate generally the same way they did with Skyrim. Any running threads
are saved so they can be resumed when the save is loaded. This means any while
loops running will be saved into the save game, because of course they need to
continue running when the save is loading. However because they are saved, any
patch to the function that you release in a mod can't be applied to that thread
until it exits the function (which means the while loop has to end).
While loops also keep the thread alive, which consumes some memory, as the
thread and all its stack data and calling functions stack data need to stick
around. If you end up with >100 threads running at once for over a few seconds,
Papyrus assumes something is wrong and starts spitting out stack dumps to the
log so you can find and fix the problem. If the while loops aren't sleeping (via
Wait or some other latent call) they can contribute to script lag as the VM has
to take time to process the thread in addition to everything else it's running.
Timers replace OnUpdate partially in response to the problems with continual
update event registrations (they are equivalent to single update registrations).
And because it's sometimes really handy to have multiple timers going at once on
different intervals.
So yes, if you need something running over a long period of time, you should be
using timer events.
All that being said, F4's version of Papyrus is much more aggressive about
cleaning out dead data if things go... missing. Not that any self-respecting
modder would do that.
</pre>
=== How do I write save-safe scripts then? ===
=== How do I write save-safe scripts then? ===
=== How would I emulate a Break statement in a While loop? ===
=== How would I emulate a Break statement in a While loop? ===

Navigation menu