[Papyrus] Singleupdate not always responsive

Post » Tue Feb 16, 2016 4:24 am

Hi, I have a problem with a script for my quest mod. I have a script that sometimes does not work. Here it is:


--------------------------------------------------

Scriptname TestScript extends Quest


ReferenceAlias Property test1 Auto

ReferenceAlias Property test2 Auto

ReferenceAlias Property test3 Auto

Quest Property quest1 Auto


Function UD()

RegisterForSingleUpdate(1)

EndFunction


Event OnInit()

SetObjectiveDisplayed(10)

UD()

EndEvent


Event OnUpdate()

If test1.GetActorReference().IsDead() == 1

If test2.GetActorReference().IsDead() == 1

If test3.GetActorReference().IsDead() == 1

quest1.SetStage(20)

Else

UD()

EndIf

Else

UD()

EndIf

Else

UD()

EndIf

EndEvent

----------------------------------------------------------------


Can the script be cancelled out by other scripts that are executed in the time between?


I also have another problem where markers don't show in the third quest in my mod (the same quest that contains the script above), even when I test it on a clean save.


Any help is appreciated. Thank you!
User avatar
meg knight
 
Posts: 3463
Joined: Wed Nov 29, 2006 4:20 am

Post » Tue Feb 16, 2016 11:34 am

I'm not sure what's causing your script to fail. The OnUpdate should only not be triggered if there is an UnregsiterForUpdate. Regardless, you don't want to be polling like that. Calling for the script to run once every second is very performance inefficient. You should use events to detect when your reference aliases die. For example:



Scriptname _test_testscript extends ReferenceAlias

Event OnDeath(Actor akKiller)
_test_testquest kQuest = GetOwningQuest() as _test_testquest ;_test_testquest is the script on the quest with these referencealiases
kQuest.incrementDeadActor()
endEvent


Scriptname _test_testquest extends Quest

Quest Property quest1 Auto

int iDeadCount

Function incrementDeadActor()
iDeadCount += 1
if iDeadCount == 3
quest1.SetStage(20)
endIf
endFunction

Also as a side note, you can use "and" in your if statements... for example:



Actor Bob
Actor Joe
Actor Sue

Function SomeFunction()
if Bob.IsDead() && Joe.IsDead() && Sue.IsDead()
;do something
else
;do something else
endIf
endFunction
User avatar
Taylor Bakos
 
Posts: 3408
Joined: Mon Jan 15, 2007 12:05 am

Post » Tue Feb 16, 2016 1:00 pm

Thanks for the reply!


I suspected that it would be performance heavy, yes, but the battle with the NPCs is going on at the same time, so I don't know which one will die last. That is why I thought it would prove difficult To have an OnDeath event for each of the six actors.


I also do not understand everything in your example scripts (I am fairly new to papyrus and programming). Is the IncrementDeadActor() function global? How did you make it global? How does the += thing in front of the iDeadCount work. Other than these things, I see how the script would work, if I apply it to the actors.



I understand if you don't want to explain all of those things. If so, thanks for the help anyway. I'm sure I'll figure it out.

User avatar
Jeff Tingler
 
Posts: 3609
Joined: Sat Oct 13, 2007 7:55 pm

Post » Tue Feb 16, 2016 12:50 am

incrementDeadActor is a function that I made in the "quest" script. It is not global. You must call it on the script that it is in. So lets say you have a quest called "MyQuest01". MyQuest01 will have the "_test_testquest" script attached to it. MyQuest01 also has three reference aliases. Each reference alias in MyQuest01 has the "_test_testscript" attached to it. Whenever one of those reference alias dies, the incrementDeadActor function is called to run from the _test_testquest script (we find the quest/script to talk to with the GetOwningQuest() function).



iDeadCount += 1 is the same as iDeadCount = iDeadCount + 1. It just increases the variable by one. Once our counter hits 3, we change the quest stage.



Edit: Also, I edited the script above as there was an error

User avatar
Emily Jones
 
Posts: 3425
Joined: Mon Jul 17, 2006 3:33 pm

Post » Tue Feb 16, 2016 2:38 pm

Ohh, now I see. Thanks for your help, it's going to make thing a lot easier. :)

User avatar
Rachel Cafferty
 
Posts: 3442
Joined: Thu Jun 22, 2006 1:48 am


Return to V - Skyrim