Desperately trying to speed up Papyrus.

Post » Thu Jun 21, 2012 3:33 am

With the release of the Beta SKSE, I've been using the IsKeyPressed() functions. However, Papyrus limits the use of this because it's polling. I'm struggling to find a way to speed up Papyrus, and If I can't my mod will probably have to be canceled. Anyone found a way to speed up Papyrus?

[Edit] Does script dragon limit scripts with polling, because that could be a good alternative?
User avatar
Anthony Santillan
 
Posts: 3461
Joined: Sun Jul 01, 2007 6:42 am

Post » Wed Jun 20, 2012 10:57 pm

OMG It's been released?!?!?

EDIT: The link on the SKSE website doesn't work. Use the link from the http://www.gamesas.com/topic/1362188-wipz-skyrim-script-extender-skse/.

EDIT2: Keeping this on topic, I just tried out the input functions with this script and it seems to work fairly well:

Scriptname fg109TestMEScript extends ActiveMagicEffectimport InputActor PlayerEvent OnEffectStart(Actor akTarget, Actor akCaster)    Player = akTarget    RegisterForSingleUpdate(0.01)EndEventEvent OnUpdate()    while (IsKeyPressed(42) || IsKeyPressed(54))    ;left shift, right shift        if (IsKeyPressed(78))                        ;num plus            Player.RestoreAV("Health", 10)        elseif (IsKeyPressed(74))                    ;num minus            Player.DamageAV("Health", 10)        endif    endwhile    RegisterForSingleUpdate(1)EndEvent
User avatar
Connor Wing
 
Posts: 3465
Joined: Wed Jun 20, 2007 1:22 am

Post » Thu Jun 21, 2012 1:17 am

Oh awesome, SKSE is offically out?

In any case, Script Dragon probably won't help simply because as far as I know, it doesn't use the default scripting language at all - it simply attaches external C++ code you write, as far as I can tell.
User avatar
Da Missz
 
Posts: 3438
Joined: Fri Mar 30, 2007 4:42 pm

Post » Thu Jun 21, 2012 9:16 am

Oh awesome, SKSE is offically out?

In any case, Script Dragon probably won't help simply because as far as I know, it doesn't use the default scripting language at all - it simply attaches external C++ code you write, as far as I can tell.
Technically a SKSE Beta... But yes.
User avatar
CArla HOlbert
 
Posts: 3342
Joined: Wed Feb 21, 2007 11:35 pm

Post » Thu Jun 21, 2012 6:12 am

Here's a temporary GetKeyPressed(). It's kinda slow, but will work for rebinding until the real thing.

Int Function iGetKeyPressed(Int aiDXScancode = 1)	While !Input.IsKeyPressed(aiDXScancode)		aiDXScancode += 1		Debug.Notification("Press and hold an unused key...")		If aiDXScancode > 265 			aiDXScancode = 1		EndIf	EndWhile	Return aiDXScancodeEndFunction

Topic: Post the script? There might be things that can be done to make each iteration run faster. Can't wait for the SKSE events.
User avatar
Nicole M
 
Posts: 3501
Joined: Thu Jun 15, 2006 6:31 am

Post » Thu Jun 21, 2012 5:43 am

OMG It's been released?!?!?

EDIT: The link on the SKSE website doesn't work. Use the link from the http://www.gamesas.com/topic/1362188-wipz-skyrim-script-extender-skse/.

EDIT2: Keeping this on topic, I just tried out the input functions with this script and it seems to work fairly well:

Scriptname fg109TestMEScript extends ActiveMagicEffectimport InputActor PlayerEvent OnEffectStart(Actor akTarget, Actor akCaster)	Player = akTarget	RegisterForSingleUpdate(0.01)EndEventEvent OnUpdate()	while (IsKeyPressed(42) || IsKeyPressed(54))	;left shift, right shift		if (IsKeyPressed(78))						;num plus			Player.RestoreAV("Health", 10)		elseif (IsKeyPressed(74))					;num minus			Player.DamageAV("Health", 10)		endif	endwhile	RegisterForSingleUpdate(1)EndEvent

I'm using a code like that but it's really slow? It can up to half a second for my keypresses to register.
User avatar
Gemma Flanagan
 
Posts: 3432
Joined: Sun Aug 13, 2006 6:34 pm

Post » Thu Jun 21, 2012 5:49 am

With the release of the Beta SKSE, I've been using the IsKeyPressed() functions. However, Papyrus limits the use of this because it's polling. I'm struggling to find a way to speed up Papyrus, and If I can't my mod will probably have to be canceled.

http://www.gamesas.com/topic/1362188-wipz-skyrim-script-extender-skse/page__view__findpost__p__20685745 that they had just figured out how to do events, and that event-based keypress functionality would be coming:

The biggest item missing from this initial release is support for new events. Ian just last night figured the basic system out, and yo can see some of it in the code. But it is not ready yet and I wanted to get the rest of the functionality into people's hands. Because there is no event support, OnKeyDown and OnKeyUp are not yet available.
User avatar
Kelly Tomlinson
 
Posts: 3503
Joined: Sat Jul 08, 2006 11:57 pm

Post » Wed Jun 20, 2012 7:51 pm

Try
Spoiler
Event OnUpdate()	If IsKeyPressed(42)  ;left shift		If IsKeyPressed(78) ; num plus			PlayerREF.RestoreAV("Health", 10)		ElseIf IsKeyPressed(74) ; num minus			PlayerREF.DamageAV("Health", 10)		EndIf	ElseIf IsKeyPressed(54) ; right shift		If IsKeyPressed(78) ; num plus			PlayerREF.RestoreAV("Health", 10)		ElseIf IsKeyPressed(74) ; num minus			PlayerREF.DamageAV("Health", 10)		EndIf	Else		RegisterForSingleUpdate(1)	EndIf	EndEvent
?

A PlayerREF Auto Property is 'cheaper' IIRC as the compiler does some optimization. I'm thinking it might run faster if not having to check multiple keys in the same line...
User avatar
Rodney C
 
Posts: 3520
Joined: Sat Aug 18, 2007 12:54 am

Post » Thu Jun 21, 2012 4:29 am

Try
Spoiler
Event OnUpdate()	If IsKeyPressed(42)  ;left shift		If IsKeyPressed(78) ; num plus			PlayerREF.RestoreAV("Health", 10)		ElseIf IsKeyPressed(74) ; num minus			PlayerREF.DamageAV("Health", 10)		EndIf	ElseIf IsKeyPressed(54) ; right shift		If IsKeyPressed(78) ; num plus			PlayerREF.RestoreAV("Health", 10)		ElseIf IsKeyPressed(74) ; num minus			PlayerREF.DamageAV("Health", 10)		EndIf	Else		RegisterForSingleUpdate(1)	EndIf	EndEvent
?

A PlayerREF Auto Property is 'cheaper' IIRC as the compiler does some optimization. I'm thinking it might run faster if not having to check multiple keys in the same line...

Would using a function speed up my script? Like, could make a script to hold functions, and then use "import" to add them in?
User avatar
Francesca
 
Posts: 3485
Joined: Thu Jun 22, 2006 5:26 pm

Post » Thu Jun 21, 2012 12:08 am

Your script is running slow because you're telling it to... change the registerForSingleUpdate in the onUpdate event to something faster (like you onActivate has). .033 gives you 30fps, IF the script fires when it should be. I've gotten scripts to successfully fire as fast as .01, so it's not the script per se (well in your case it is), but the overload on the system.

We've be having quite a heated discussion as to how fast things can be pressed, what affects that speed, and what happens when it runs too slow. See the NavMesh Bug #4 thread, or one of my mod's discussion threads at http://skyrim.nexusmods.com/downloads/file.php?id=5432. We've established that DETAIL LEVEL causes slow-down and errors in scripting... how and why this can be is what the current discussion is mainly about.

As far as FORCING it to go as fast as it possibly can; it won't go ANY faster than if you put a block of code in a while-loop... it fires as soon as it's finished (granted the system has an open thread for it to run again). There's also the possibility (probability in MY opinion) that SKSE is slowing it down... Papyrus is seemingly so sensitive that something as hard-core and intrusive as SKSE will probably cause drama - at least in the earlier versions.
User avatar
ANaIs GRelot
 
Posts: 3401
Joined: Tue Dec 12, 2006 6:19 pm

Post » Thu Jun 21, 2012 8:10 am

Your script is running slow because you're telling it to... change the registerForSingleUpdate in the onUpdate event to something faster (like you onActivate has). .033 gives you 30fps, IF the script fires when it should be. I've gotten scripts to successfully fire as fast as .01, so it's not the script per se (well in your case it is), but the overload on the system. We've be having quite a heated discussion as to how fast things can be pressed, what affects that speed, and what happens when it runs too slow. See the NavMesh Bug #4 thread, or one of my mod's discussion threads at http://skyrim.nexusmods.com/downloads/file.php?id=5432. We've established that DETAIL LEVEL causes slow-down and errors in scripting... how and why this can be is what the current discussion is mainly about. As far as FORCING it to go as fast as it possibly can; it won't go ANY faster than if you put a block of code in a while-loop... it fires as soon as it's finished (granted the system has an open thread for it to run again). There's also the possibility (probability in MY opinion) that SKSE is slowing it down... Papyrus is seemingly so sensitive that something as hard-core and intrusive as SKSE will probably cause drama - at least in the earlier versions.

Changing the update time to 0.033 didn't do anything. But doing the While method did speed up the responsiveness. I think I'm just going to wait for OnKeyPress() for SKSE.
User avatar
Suzie Dalziel
 
Posts: 3443
Joined: Thu Jun 15, 2006 8:19 pm

Post » Thu Jun 21, 2012 9:08 am

If setting the script to run 30 times per second (versus once/sec) didn't help, then it sounds like you have 'script interference' coming from elsewhere. If you're using a bunch of poorly scripted mods, or if your game's fps falls below 30-35 (believe it or not), your script won't fire when it should, but at the first available chance it gets. And again, it's possible that SKSE itself is causing the slowdown... I believe they use custom functions to achieve certain things; so there are more blocks of code running than without it.

It doesn't really have anything to do with the command you're actually running (inKeyPressed/etc), but the overall state of your system and the game-engine. Maxing out system memory while playing will cause this as well; and of course if you max out your CPU.

ONE more thing you need to consider... and THIS may be your actual cause... by placing a while loop, the script may be iterating so many times, while you have the shiftkey held down - that it lags because it has to catch up all the stacked firings. I actually exploit this stacking aspect of Papyrus to achieve my sailing script, but for what you want...

[EDIT: I would try changing the while loop to an if loop... since the script fires so rapidly anyway. That way, you press shift.. the script keeps firing while it's held down; you press +, the script fires your health booster, then keeps firing. Since you only pressed + once, the script will go back to checking for it again. I think that while loop is overkill... but it may not make a difference either way, for the aforementioned reasons.]
User avatar
Cameron Garrod
 
Posts: 3427
Joined: Sat Jun 30, 2007 7:46 am


Return to V - Skyrim