Jump to content

[Scripting] Utility.Wait behaving... unexpected?


Nymra

Recommended Posts

Posted

Ok, so I m still totally new to alot of the underlying stuff of scripts.

 

I read in CreationKit, that Utility.Wait can be slow when Papyrus Load is high.

So it can be that Utility.Wait(1) (second) becomes like 3 seconds, correct?

 

Or is there some more to it?

 

For example when I have TWO functions in ONE script that BOTH run at the same time and BOTH have Utility.Wait(X) in them,

will they also delay each other?

 

So if I have 2x Utility.Wait(3.0) in the same script at the same time, can it be that the one Function will affect the delay of the other Function because it is in the same script?

 

Reasoning behind is: I am getting very odd results when using "utility.wait", where it can range from 1 second is 1 second up unto 1 second is almost 5 seconds...

 

Question is also, if it will be beneficial to use "RegisterforSingleUpdate" to wait a period of time or if there is some better, more accurate method with using Realtime? 

Posted

Multithreading is a thing in Papyrus. One execution wont cause the other one to hold - unless they are operating in the same thread; read: are part of the same execution chain

 

If you have 2 spells and cast both at the same time, both triggering some script with Utility.Wait() in them, even when both scripts are using the same script or even the same function, one wont stop the other to execute since they both operate in their own thread

 

33 minutes ago, Nymra said:

So it can be that Utility.Wait(1) (second) becomes like 3 seconds, correct?

If youre playing on a toaster running on Win95, in the middle of Sahara desert during the day with energy safe mode throttling the CPU speed by 90%, perhaps. I wouldnt bet on it though

 

The CK likes to overdramatize. People like to overdramatize. In a Papyrus environment this delay that could be created can be ignored and if not: your design should prbly go back onto the drawing board

Id be more than just suprised if Utility.Wait() is exact. Theres likely always an additional delay of a couple hundred us and the game throttling down the Papyrus engine due to overhead will likely slow down those Wait() calls by a couple ms at most. If your mod breaks on that, rethink your design

 

Posted

I had never any problems using Utility.wait () for the smaller amounts of time where it is intended for, except when you open a menu !

If that case the waiting time does not run, instead you must use some call Utility.waitmenumode (or similar)

 

Regarding the example with the spells using the same script. The Creation kit says any call to an external function not using the same "root" can result

in stopping execution of the script and continue with some other script. If that is true for Utility.wait () also I do not know.

For that case all semaphores  used for  synchronising threads on the same script must be local in the script ! Otherwise,theydo  not work reliable.

(--> An unfixed  bug in  Kimy's DD for Fallout 4 using a global as semaphore) External calls can be  functions from other scripts, globals but also  any  usage of properties in your script since the engine uses getter and setter functions.

Posted
3 hours ago, Kanlaon said:

I had never any problems using Utility.wait () for the smaller amounts of time where it is intended for, except when you open a menu !

If that case the waiting time does not run, instead you must use some call Utility.waitmenumode (or similar)

 

Regarding the example with the spells using the same script. The Creation kit says any call to an external function not using the same "root" can result

in stopping execution of the script and continue with some other script. If that is true for Utility.wait () also I do not know.

For that case all semaphores  used for  synchronising threads on the same script must be local in the script ! Otherwise,theydo  not work reliable.

(--> An unfixed  bug in  Kimy's DD for Fallout 4 using a global as semaphore) External calls can be  functions from other scripts, globals but also  any  usage of properties in your script since the engine uses getter and setter functions.

 

 

I m using "SendModEvent" to start a Function.

So Script X

 

bool RunThisFunction = true

 

Function A()

SendsModEvent("StartFunctionB")

 

while FunctionBrunning == true

Utility.Wait(1)
EndWhile 

 

EndFunction

 

Function B()


while RunThisFunction == true
Utility.Wait(1)
EndWhile 


EndFunction 

ok this is very basic but I hope I can bring across what I m doing, hehe. 

Basically Function A makes the PC wait for X seconds (with a "while" loop counting down
Function B checks stuff while A is running (it has to be checked only once,,.. so). Argh.
ok sorry, might be confusing.

basically 2 functions of same script have a parallel
while x
utility.wait(1.0)

endwhile 
running at the same time

Posted
54 minutes ago, Nymra said:

 

 

I m using "SendModEvent" to start a Function.

So Script X

 

bool RunThisFunction = true

 

Function A()

SendsModEvent("StartFunctionB")

 

while FunctionBrunning == true

Utility.Wait(1)
EndWhile 

 

EndFunction

 

Function B()


while RunThisFunction == true
Utility.Wait(1)
EndWhile 


EndFunction 

ok this is very basic but I hope I can bring across what I m doing, hehe. 

Basically Function A makes the PC wait for X seconds (with a "while" loop counting down
Function B checks stuff while A is running (it has to be checked only once,,.. so). Argh.
ok sorry, might be confusing.

basically 2 functions of same script have a parallel
while x
utility.wait(1.0)

endwhile 
running at the same time

 

Hallo,

 

Wenn das ein Auszug aus deiner aktuellen Arbeit ist, dann schick mir besser mal einen kompletten übersetzbaren Zip File oder poste den hier

Jedenfalls aufgefallen ist mir: Nach dem Sendmodevent geht es sofort mit der Warteschleife los. Ich würde vermuten, daß der 2. Teil dann noch gar nicht

von der Engine weiterverarbeitet wurde.

FunctionBrunning Set & Reset und das Reset von RunThisFunction ist hier jedenfalls nicht sichtbar.

 

Ob es gut ist, die EventEngine für die Funktion B zu belasten weiß ich auch nicht.

Jedenfalls hat Bethesda für Fallout 4 da viel dran 'geschraubt' bzw. geändert um eine

bessere Performance zu bekommen.

Vielleicht gibt es ja auch eine ganz anderen Lösungsansatz für die Funktionalität in deinem Mod :)

 

Grüße

 

Posted

If you want correct results, use realtime. Utility.Wait will only really be correct if the script engine and havok is idle.

Posted
2 hours ago, Andy14 said:

If you want correct results, use realtime. Utility.Wait will only really be correct if the script engine and havok is idle.

 

something along these lines?

and I guess I cannot completly avoid Utility.Wait even in this case, hmm

would it be totally papyrus breaking if this operaiton would be even faster, like Wait(0.01) to increase accuracy?

 

I really would like to be able to count a time of 2-20 seconds with best accuracy possible.
its not mod breaking that Utility.Wait does not do it, but a little annoyance :P 

 

Function RealWaiting(float WaitTime)

float ftimeStart = Utility.GetCurrentRealTime()
float ftimeCurrent = 0

while ftimeCurrent < (ftimeStart + WaitTime)
Utility.Wait(0.1)
ftimeCurrent = Utility.GetCurrentRealTime()
endwhile

EndFunction

 

I also found this which also talks about "real world seconds" but not sure what exctly this is or how to use :P

 

https://www.creationkit.com/index.php?title=Wait_(Procedure)

Posted
1 hour ago, Nymra said:

 

something along these lines?

and I guess I cannot completly avoid Utility.Wait even in this case, hmm

would it be totally papyrus breaking if this operaiton would be even faster, like Wait(0.01) to increase accuracy?

 

I really would like to be able to count a time of 2-20 seconds with best accuracy possible.
its not mod breaking that Utility.Wait does not do it, but a little annoyance :P 

 

Function RealWaiting(float WaitTime)

float ftimeStart = Utility.GetCurrentRealTime()
float ftimeCurrent = 0

while ftimeCurrent < (ftimeStart + WaitTime)
Utility.Wait(0.1)
ftimeCurrent = Utility.GetCurrentRealTime()
endwhile

EndFunction

 

I also found this which also talks about "real world seconds" but not sure what exctly this is or how to use :P

 

https://www.creationkit.com/index.php?title=Wait_(Procedure)

 

As  far  as I know the Wait Procedure is used in AI-Packages. So maybe not useful for your purpose.

I do not know how many of your functions A and B can run at thesame time.

If it is only one couple simply use the solution in CK for the Reatime :  Store Starting time when Function B starts, and store Ending time when this function ends thenncalculate the difference.

 

And since Both functions reside in the same script, I guess Registerforsingleupdate is not an option, since you can not destinguish in the OnUpdate which of the Registerfunctions

causes the event to fire, but instead you could use it to forward the end of function B to function A.

 

 

 

Posted
6 hours ago, Nymra said:

 

something along these lines?

and I guess I cannot completly avoid Utility.Wait even in this case, hmm

would it be totally papyrus breaking if this operaiton would be even faster, like Wait(0.01) to increase accuracy?

 

I really would like to be able to count a time of 2-20 seconds with best accuracy possible.
its not mod breaking that Utility.Wait does not do it, but a little annoyance :P 

 

Function RealWaiting(float WaitTime)

float ftimeStart = Utility.GetCurrentRealTime()
float ftimeCurrent = 0

while ftimeCurrent < (ftimeStart + WaitTime)
Utility.Wait(0.1)
ftimeCurrent = Utility.GetCurrentRealTime()
endwhile

EndFunction

 

I also found this which also talks about "real world seconds" but not sure what exctly this is or how to use :P

 

https://www.creationkit.com/index.php?title=Wait_(Procedure)

Ja, in dieser Art.

Und tatsächlich braucht man auch hier Utility.Wait um der Schleife etwas Zeit zu schaffen, oder besser gesagt, Zeit zu vergeuden. ;) 

Posted

When playing Skyrim I had often problems with big script lags, depending on what mods are installed.

Sometimes up to 8-9 Seconds until something happens, when you expect it immediately.

 

I do not know if a measuring tool for script latency exist in Skyrim, but for Fallout 4 there is one !!

 

https://www.nexusmods.com/fallout4/mods/35853

 

The mod is very small and does not contain a dll.

Therefore I think I could make a version for Skyrim, provided the author gives permission.

The constructible Objects in this mod would not be necessary for Skyrim since there is the excellent AdditemMenu mod.

 

Posted
On 5/7/2022 at 9:37 PM, Nymra said:

Basically Function A makes the PC wait for X seconds (with a "while" loop counting down
Function B checks stuff while A is running (it has to be checked only once,,.. so). Argh.
ok sorry, might be confusing.

Zen of python:

If the implementation is hard to explain, it's a bad idea.
 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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