What would be a "safe" RegisterForSingleUpdate time?

Post » Tue Aug 12, 2014 4:19 am

I'm currently making a magic effect mod to Miraak's boots that causes the wearer to leave a damaging trail of lightning in their wake during combat. The way I'm currently doing this is to use RegisterForSingleUpdate to constantly check if the wearer is in combat, and if true, to then constantly place a short-lived hazard object using PlaceAtMe. There's also additional checks to see if the wearer is sneaking (won't place hazard), running or sprinting (places hazard faster by using a shorter time on RegisterForSingleUpdate).

Since the time needs to be quite short to simulate a continuous "trail" I'm worried that the script could cause save game bloating, as outlined on the wiki page. As is, the timer property value I'm currently using is WaitTimer = 0.3, and that timer is even shorter if running (= 0.2) or sprinting (= 0.1).

Scriptname aaaMiraakStormWalkHazardPlacer extends ActiveMagicEffect  Hazard Property HazardtoPlace  Auto  Float Property WaitTimer  AutoActor selfrefBool bKeepUpdating Event OnEffectStart(actor target, actor caster)	RegisterForSingleUpdate(WaitTimer)	bKeepUpdating = TrueEndEventEvent OnUpdate()selfref = (gettargetactor())	if (selfref.IsInCombat() == True) 		if (selfref.issneaking() == False)			selfref.placeatme(HazardtoPlace)		endif	endif	if bKeepUpdating		if (selfref.isrunning() == True)			RegisterForSingleUpdate(WaitTimer*(2/3)		elseif (selfref.issprinting() == True)			RegisterForSingleUpdate(WaitTimer/3)		else			RegisterForSingleUpdate(WaitTimer)		endif	endifEndEvent  Event OnEffectFinish(actor target, actor caster)	bKeepUpdating = falseEndEvent

So, how safe am I?

User avatar
ezra
 
Posts: 3510
Joined: Sun Aug 12, 2007 6:40 pm

Post » Tue Aug 12, 2014 2:49 am

I would generally recommend not going below 1 second to be safe.

However, I may have a better solution, have you tried this instead? http://www.creationkit.com/OnCombatStateChanged_-_Actor

It's an event that fires when the combat stage changes. You could use it to detect the change to 'in combat', apply your stuff, then detect 'not in combat' to remove your stuff. No need for these crazy updates and it should react almost instantly.

User avatar
Tarka
 
Posts: 3430
Joined: Sun Jun 10, 2007 9:22 pm

Post » Tue Aug 12, 2014 9:18 am

That was actually my first plan, but the wiki page says it won't work for the player.

EDIT: Do you think replacing the update-loops with some sort of while-loop coupled with utility.wait would work better?

User avatar
Shianne Donato
 
Posts: 3422
Joined: Sat Aug 11, 2007 5:55 am

Post » Tue Aug 12, 2014 3:23 am

I wouldn't trust OnEffectFinish to handle ending the registration. You could perhaps end it in the OnUpdate itself under certain conditions. If OnEffectFinish is ran consistently for you, then stick with it.

User avatar
Alyce Argabright
 
Posts: 3403
Joined: Mon Aug 20, 2007 8:11 pm

Post » Tue Aug 12, 2014 2:34 am

I was under the impression that bloat ocurred when the function in the update takes longer to run than the update interval, usually associated with RegisterForUpdate()

Placing RegisterForSingleUpdate() at the end allows the function to fully complete before the new update takes place.

I can confirm OnCombatStateChanged doesn't work for the player.

User avatar
JUan Martinez
 
Posts: 3552
Joined: Tue Oct 16, 2007 7:12 am


Return to V - Skyrim