Difference between revisions of "User:DavidJCobb/Stack dumping"
code snippet for BF
imported>DavidJCobb m (→Events that can trigger large numbers of suspended stacks: OnHit's concurrency has been experimentally verified. Item events' consecutive...ness... has not.) |
imported>DavidJCobb (code snippet for BF) |
||
Line 35: | Line 35: | ||
** For OnItemAdded and OnItemRemoved, I list some additional methods for avoiding stack dumping [[Talk:OnItemAdded - ObjectReference#Facts about OnItemAdded|here]]. | ** For OnItemAdded and OnItemRemoved, I list some additional methods for avoiding stack dumping [[Talk:OnItemAdded - ObjectReference#Facts about OnItemAdded|here]]. | ||
** OnItemAdded and OnItemRemoved don't appear to be able to run concurrently with themselves, so their stacks will be suspended as a matter of course. | ** OnItemAdded and OnItemRemoved don't appear to be able to run concurrently with themselves, so their stacks will be suspended as a matter of course. | ||
== Miscellaneous facts == | == Miscellaneous facts == | ||
* RegisterForSingleUpdate(''n'') does ''not'' create a stack and suspend it for ''n'' seconds. I have confirmed this experimentally. | * RegisterForSingleUpdate(''n'') does ''not'' create a stack and suspend it for ''n'' seconds. I have confirmed this experimentally. | ||
== Code snippets == | |||
=== Process a task OnHit, and don't re-process for X seconds === | |||
<source lang="Papyrus"> | |||
Bool Property pbBusy = False Auto Hidden | |||
Bool Property pbProcessed = False Auto Hidden | |||
Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, Bool abPowerAttack, Bool abSneakAttack, Bool abBashAttack, Bool abHitBlocked) | |||
If pbBusy || pbProcessed | |||
Return | |||
EndIf | |||
pbBusy = True | |||
; | |||
; Do your processing here. | |||
; | |||
pbProcessed = True | |||
RegisterForSingleUpdate(x) | |||
pbBusy = False | |||
EndEvent | |||
Event OnUpdate() | |||
pbProcessed = False | |||
EndEvent | |||
</source> |