On the run-time of Skyrim's Papyrus Scripts

Post » Wed Jun 20, 2012 8:26 am

Hey,

Are you a mod user who has sometimes run into scripts reacting slowly in mods? Or are you a mod author using scripts in your mods and have you had people reporting script lag to you? Or are you just interested in some information about the time it takes for skyrim's scripts to run? :tongue:

Take a look here: http://dl.dropbox.com/u/49019227/Skyrim_Papyrus_Scripts_Runtime.pdf

I'll also post this on the Creation Kit wiki if I manage to figure out how to do that :tongue:

EDIT: actually, if someone else could put it on CK wiki in the correct spot, would be cool :P
User avatar
Kara Payne
 
Posts: 3415
Joined: Thu Oct 26, 2006 12:47 am

Post » Wed Jun 20, 2012 8:11 am

Well done, Borgut!

What do you think of the liberal use of States?

It's a coding method I use a lot not only in modding this game but also in my profession.
I used that method in Oblivion with a variable (functionMode) and now I use it in Skyrim with either Papyrus' State code-blocks or with variables.
How I use this method: I break-up my mod's intended effects over several "steps".
For example, if I need to add a detrimental Ability to the player (e.g. Arm injury), I detect the health-loss in one State then apply the Ability in the next State.
Breaking up your mod actions in to smaller chunks not only ensures that the CPU time-slices in your Script are short but also that you can have your mod run at very short intervals (e.g. RegisterForSingleUpdate (0.5))
User avatar
Alycia Leann grace
 
Posts: 3539
Joined: Tue Jun 26, 2007 10:07 pm

Post » Wed Jun 20, 2012 8:26 am

If I understand you correctly, you're doing something like this:

RegisterForUpdate(0.5)auto State state1	 Event OnUpdate()		  DoStuff()		  goToState("state2")	 EndEventEndStateState state2	 Event OnUpdate()		  DoStuff2()		  goToState("state1")	 EndEventEndState

instead of

RegisterForUpdate(1)Event OnUpdate()	 DoStuff()	 DoStuff2()EndEvent

So if you need to do 2 things at 1 second intervals, instead you use 0.5 second intervals and alternatingly do the first thing and the second thing? Or am I totally missing your point here? :P
User avatar
Spaceman
 
Posts: 3429
Joined: Wed May 23, 2007 10:09 am

Post » Wed Jun 20, 2012 4:05 am

States can do a lot more than that...he can define functions that change depending on which one it's in when he calls it (which could be pretty random if he's toggling back and forth twice a second)
User avatar
x_JeNnY_x
 
Posts: 3493
Joined: Wed Jul 05, 2006 3:52 pm

Post » Wed Jun 20, 2012 1:19 am

Well done, Borgut!

What do you think of the liberal use of States?

It's a coding method I use a lot not only in modding this game but also in my profession.
I used that method in Oblivion with a variable (functionMode) and now I use it in Skyrim with either Papyrus' State code-blocks or with variables.
How I use this method: I break-up my mod's intended effects over several "steps".
For example, if I need to add a detrimental Ability to the player (e.g. Arm injury), I detect the health-loss in one State then apply the Ability in the next State.
Breaking up your mod actions in to smaller chunks not only ensures that the CPU time-slices in your Script are short but also that you can have your mod run at very short intervals (e.g. RegisterForSingleUpdate (0.5))

I could be wrong, but I think if you're using RegisterForSingleUpdate, there isn't much advantage to dividing up your actions like that. Lets say you have a really heavy function that takes a while to run (I put together one that builds up some form lists that took about 5 seconds before I optimized it.) If you call RegisterForUpdate(0.5) its going to stack up like crazy, but if you use RegisterForSingleUpdate(0.5), you won't register for the next update until its done, so no stacking. It'll just run in the background alongside all of the other scripts that are executing. If you chopped it up into three or four pieces in different states, you're still going to have the same code running in the background, it'll just take a bit longer due to the extra 0.5 second pauses between states.

If scripts still executed sequentially, it'd be another story, but they execute simultaneously, so no longer how long it takes to execute your script, it's not going to hold anything else up.

*Edit - I guess one advantage though is that, while you're waiting between states, the data in that script becomes accessible to other threads. There are other ways around that though, like having most of your code in a function that's part of another script, and calling that function rather than having the all of the code in the same script.
User avatar
Greg Cavaliere
 
Posts: 3514
Joined: Thu Nov 01, 2007 6:31 am

Post » Wed Jun 20, 2012 4:00 pm

More pressing is the problem of States' liberal use of power over their populace, regardless of their location along the "Left-Right" spectrum. :wink:

...but that would be a discussion for another place.

Borgut1337, thank you for sharing this information. It helps explain something recently plaguing me.
User avatar
Princess Johnson
 
Posts: 3435
Joined: Wed Feb 07, 2007 5:44 pm


Return to V - Skyrim