Jump to content

script: RegisterForUpdate am i save?


h4n4

Recommended Posts

Just to doublecheck:

I want to apply a constant effect to an actor that checks periodically if a statement is true. Is my logic correct and is it ok to do this or does it slow down the game/can corrupt savegames?

I want to check the ingame time and/or daylight level(sundamage). I looked at Cheskos WL script but there is a lot of stuff in there...

Event OnEffectStart(Actor _target, Actor _caster)
  RegisterForUpdate(30.0)
EndEvent
Event OnUpdate()
  If statement == true
    DoStuff
  EndIf
EndEvent

I have read the warnings on http://www.creationkit.com/RegisterForUpdate_-_Form and i think it is better to use RegisterForSingleUpadte(30.0)

how do i make sure the update is triggered in somewhat usefull intervals? would it better to use someting like "Utility.Wait(30)" or just chain singelUpdates?

Event OnEffectStart(Actor _target, Actor _caster)
  RegisterForSingleUpdate(30.0)
EndEvent
Event OnUpdate()
  If statement == true
    DoStuff
  EndIf
;Utility.Wait(30) ???
RegisterForSingleUpadte(30.0)

and i would add

Event OnCellDetach()
    UnregisterForUpdate()
EndEvent

OnUnload()
    UnregisterForUpdate()
EndEvent

OnDeath(Actor akKiller)
    UnregisterForUpdate()
EndEvent

is this cool or will i corrupt savegames?

Edited by h4n4
Link to comment
Share on other sites

The RegisterForSingleUpdate is preferable. Otherwise if a user removes your mod while the update loop is going, their papyrus log will continue to spam errors for the life of that character run. With RegisterForSingleUpdate you don't even need to unregister. A mod removed mid update loop will only error once because there is no new call to run the update. Tho you can unregister for the single update if you really want.

 

I'd suggest against an additional wait. The register already waits for X amount of time before running the update event. If you want it to check every 30 seconds then put 30 in for the register.

 

Then again being a constant effect script might have a different result with the update loop than a standard script on a reference object. I believe that when the spell is cancelled the update loop would stop even if it was not a single update. Only way to know tho is to test.

 

To answer the question: The single update chain is less likely to cause issues for the end user.

 

Those are my thoughts at any rate... Use with a grain of salt... or a full truckload depending upon road conditions :P

Link to comment
Share on other sites

year... ill just put a few RegisterForUpdate loop into each other and place them on a naked body - upload to nexus and see what happens...

 

No seriously. Thx ill take the single chain.

 

ill put

Event OnEffectFinish(Actor _target, Actor _caster)
    UnregisterForUpdate()
EndEvent

in as well so there are no fency thing happening after i finished

Edited by h4n4
Link to comment
Share on other sites

wait what happens if i add the magic effect that runs the RegisterForSingleUpdate chain script multiple times to an actor (is it even possible?)

does this cause multiple loops? i added a check to not do that but you never know

Edited by h4n4
Link to comment
Share on other sites

Each form that calls to register for an update of any kind can only have one wait before the update event. So if you register for 30 seconds and then 15 seconds later register another 30 seconds, the form will wait a total of 45 seconds before running the update event.

 

Are magic effects treated as separate forms or are they treated with the object they are cast upon? I honestly do not know. They may be similar to quest alias scripts in that they'll be treated as the object attached to for the life of the magic effect. If that is the case then multiple registers would only push the time to wait before the update event takes place.

 

You'll have to test and see what happens.

Link to comment
Share on other sites

Depending on what your "statement" is, it may be preferable to use a condition function on the spell effect. A conditional is evaluated every second as long as the spell is active without the need for scripting.

 

Edit: I missed in the OP where you said what you want to check for. I would suggest looking at the Sun Damage spell (VampireSunDamage01) and checking out the condition functions it uses. They are:

 

GetInWorldSpace Formlist:SunDamageExceptionWorldSpaces == 0 AND

GetGlobalValue GameHour <= 19 AND

GetGlobalValue GameHour >= 5 AND

IsInInterior == 0

 

In other words, the effect is applied as long as the target of the spell is not in a specific list of locations, not in an interior, and the game time is between 5am and 7pm.

 

http://www.creationkit.com/Condition

Edited by lofgren
Link to comment
Share on other sites

yeaf thas a cool way to do it.

but then you would loose the effect if the condition is untrue right? with a update i can stick that to the actor "for ever"

Edited by h4n4
Link to comment
Share on other sites

Yes, if the condition is untrue then the effect will end, but it will start up again as soon as the conditions are true again (just like vampire sun damage).

hm yeah. That definetly a better option for some effects. Ill will check out if i can confort some parts of my mod to that (im sure i need at least one update chain at some point) once have time to overlook averything again.

Link to comment
Share on other sites

It is better for simple effects. If you want your spell do one thing if the player has sun damage, and something else if the player does not have sun damage, then an update chain might be better. If the spell is only going to be on or off then conditions are probably better.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...