• Announcements

    • Ashal

      SITE MOVED - IN READ ONLY MODE   12/08/2015

      Please use http://www.loverslab.com moving forward. Site has been restored to a previous version, and this one placed into a read-only mode. This is available for a limited time so users may reference/copy content that has been lost in the transition. This will no longer be accessible by December 22nd, 2015.
Sign in to follow this  
Followers 0
Inte

Which Script Would Be Faster?

Ok, here is my dilemma.

I made 2 versions of the same script that will fetch a DD (with no dependency).

Script No. 1

 Scriptname iDDeLibs Extends QuestImport Game iDDeUtilities Property iDDeUtil AutoFORM[] Property iDDeBlindFold Auto Hidden;BlindFold;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbFunction iDDeSetBlindFold()   iDDeBlindFold = NEW FORM[19]	If (iDDeUtil.iDDeGotMod("iDDeSetBlindFold()", "Devious Devices - Integration.esm"))		zadLibs Libs = None		Libs = GetFormFromFile(0x0000F624, "Devious Devices - Integration.esm") AS zadLibs				iDDeBlindFold[0] = None				iDDeBlindFold[1] = Libs.blindfold	EndIf		If (iDDeUtil.iDDeGotMod("iDDeSetBlindFold()", "Devious Devices - Expansion.esm"))		zadxLibs xLibs = None		xLibs = GetFormFromFile(0x0000CA01, "Devious Devices - Expansion.esm") AS zadxLibs				iDDeBlindFold[2] = xLibs.eboniteBlindfold			iDDeBlindFold[3] = xLibs.EbblindfoldUnlocked			iDDeBlindFold[4] = xLibs.EbblindfoldBlocking			iDDeBlindFold[5] = xLibs.blindfoldUnlocked			iDDeBlindFold[6] = xLibs.blindfoldBlocking			iDDeBlindFold[7] = xLibs.wtEboniteBlindfold			iDDeBlindFold[8] = xLibs.WTEblindfoldUnlocked			iDDeBlindFold[9] = xLibs.WTEblindfoldBlocking			iDDeBlindFold[10] = xLibs.wtLeatherBlindfold			iDDeBlindFold[11] = xLibs.WTLblindfoldUnlocked			iDDeBlindFold[12] = xLibs.WTLblindfoldBlocking			iDDeBlindFold[13] = xLibs.rdEboniteBlindfold			iDDeBlindFold[14] = xLibs.RDEblindfoldUnlocked			iDDeBlindFold[15] = xLibs.RDEblindfoldBlocking			iDDeBlindFold[16] = xLibs.rdLeatherBlindfold			iDDeBlindFold[17] = xLibs.RDLblindfoldUnlocked			iDDeBlindFold[18] = xLibs.RDLblindfoldBlocking	EndIfEndFunction ;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
Here after calling the iDDeGetBlindFold at game load I would just access each form directly i.e.

To get the red Ebony Blindfold I would just call it like so,

iDDeBlindFold[13]

Script No. 2

Scriptname iDDeLibs Extends QuestImport Game iDDeUtilities Property iDDeUtil Auto;BlindFold;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbForm Function iDDeGetBlindFold(Actor Slave, INT iBlind = 0)	Form Eqp = None		If (iBlind < 2)			If (iDDeUtil.iDDeGotMod("iDDeGetBlindFold()", "Devious Devices - Integration.esm"))				zadLibs Libs = None				Libs = GetFormFromFile(0x0000F624, "Devious Devices - Integration.esm") AS zadLibs						If (iBlind <= 0)						ElseIf (iBlind == 1)						Eqp = Libs.blindfold					EndIf			EndIf		Else				If (iDDeUtil.iDDeGotMod("iDDeGetBlindFold()", "Devious Devices - Expansion.esm"))				zadxLibs xLibs = None				xLibs = GetFormFromFile(0x0000CA01, "Devious Devices - Expansion.esm") AS zadxLibs						If (iBlind == 2)							Eqp = xLibs.eboniteBlindfold					ElseIf (iBlind == 3)						Eqp = xLibs.EbblindfoldUnlocked					ElseIf (iBlind == 4)						Eqp = xLibs.EbblindfoldBlocking					ElseIf (iBlind == 5)						Eqp = xLibs.blindfoldUnlocked					ElseIf (iBlind == 6)						Eqp = xLibs.blindfoldBlocking					ElseIf (iBlind == 7)						Eqp = xLibs.wtEboniteBlindfold					ElseIf (iBlind == 8)						Eqp = xLibs.WTEblindfoldUnlocked					ElseIf (iBlind == 9)						Eqp = xLibs.WTEblindfoldBlocking					ElseIf (iBlind == 10)						Eqp = xLibs.wtLeatherBlindfold					ElseIf (iBlind == 11)						Eqp = xLibs.WTLblindfoldUnlocked					ElseIf (iBlind == 12)						Eqp = xLibs.WTLblindfoldBlocking					ElseIf (iBlind == 13)						Eqp = xLibs.rdEboniteBlindfold					ElseIf (iBlind == 14)						Eqp = xLibs.RDEblindfoldUnlocked					ElseIf (iBlind == 15)						Eqp = xLibs.RDEblindfoldBlocking					ElseIf (iBlind == 16)						Eqp = xLibs.rdLeatherBlindfold					ElseIf (iBlind == 17)						Eqp = xLibs.RDLblindfoldUnlocked					ElseIf (iBlind == 18)						Eqp = xLibs.RDLblindfoldBlocking					EndIf			EndIf		EndIf	RETURN EqpEndFunction ;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 
Here to get the same red Ebonite blindfold I would call it like so,

iDDeGetBlindFold(Slave, 13)

So ... which would be faster?

0

Share this post


Link to post

The first one no doubt.

Here's the reason, one operation...

iDDeBlindFold[2] = xLibs.eboniteBlindfold (1)

versus two...

If (iBlind == 2) (1)
Eqp = xLibs.eboniteBlindfold (2)

If iBlind is 18, too many unnecessary comparison operations will take place.

I'd also place the line iDDeBlindFold = NEW FORM[19] somewhere outside of the Function.

0

Share this post


Link to post

That makes sense.


But, here is what I was thinking;


 


Script No. 1 fills all those forms (armor) into an array of 20 items, and although calling each one individually is way faster (true), doesn't having that many forms loaded at once make it slower in the long run?


 


Script No. 2 does not fill up anything, and although calling each form individually is way slower (especially if the form is at the end of the list like you say), not having anything loaded shouldn't that make it faster in the long run?  


 


 


  


0

Share this post


Link to post

 

Script No. 1 fills all those forms (armor) into an array of 20 items, and although calling each one individually is way faster (true), doesn't having that many forms loaded at once make it slower in the long run?

 

No, having 19 forms in memory will not slow down anything, but will you keep calling this script? Isn't calling it once (on mod installation stage and/or via the MCM) to fill the array enough for this purpose? If you're going to call it more than once, take the NEW FORM[19] out of the function as I've mentioned. You only need to create the array once. If you keep calling NEW FORM[], you'll be creating new arrays but only the last one will be accessible via the iDDeBlindFold variable. Possible memory leak.

 

0

Share this post


Link to post

No I will only call the script (No. 1, and every function in it ) once on game load, then I will only call the array property directly.  


 


 


0

Share this post


Link to post

No I will only call the script (No. 1, and every function in it ) once on game load, then I will only call the array property directly.  

Don't call the entire thing on every game load. At least put something like If (!DDBlindfoldArrayLoaded) on top of the script to make it run once.

0

Share this post


Link to post

I did not think that the array would stay intact between game loads.
Do you think hidden properties get saved into the savegame?

I could probably do something like this to check if anything inside the array.
 

If (iDDeBlindFold.Length < 1)   iDDeSetBlindFold()EndIf
0

Share this post


Link to post

 

Don't call the entire thing on every game load. At least put something like If (!DDBlindfoldArrayLoaded) on top of the script to make it run once.

 

 

 

Slightly better approach is to check it on a OnPlayerLoadGame() event attached to a Ref Alias for the player.

 

So you check if the mods are there when the game loads, check what you already have, and execute accordingly.

 

I how your function will run only once per game, of course.

 

If you follow this approach then your mod can handle the case an user will uninstall a mod and install another.

0

Share this post


Link to post

The first one no doubt.

I'd also place the line iDDeBlindFold = NEW FORM[19] somewhere outside of the Function.

I'm fairly sure that has to be inside of a function or an event, otherwise I will get an error and it won't compile.

Don't call the entire thing on every game load. At least put something like If (!DDBlindfoldArrayLoaded) on top of the script to make it run once.

 

Slightly better approach is to check it on a OnPlayerLoadGame() event attached to a Ref Alias for the player.

 

~snip~

Yeap, that was my plan ... the question is, should I check if the array is filled, or should I just fill it every time when OnPlayerLoadGame() gets called.

0

Share this post


Link to post

 

Yeap, that was my plan ... the question is, should I check if the array is filled, or should I just fill it every time when OnPlayerLoadGame() gets called.

 

 

Keep an Int to check if the array is filled, and create it ONLY ONCE. Never create it twice.

 

Crating an array is time and memory consuming. Filling it is fast enough. Checking an integer is super-fast.

0

Share this post


Link to post

The first one no doubt.

I'd also place the line iDDeBlindFold = NEW FORM[19] somewhere outside of the Function.

I'm fairly sure that has to be inside of a function or an event, otherwise I will get an error and it won't compile.

Right, then you'll have to create the array elsewhere and keep it. Place it in a function that runs only once. Attach it to your main quest or something.

0

Share this post


Link to post
Sign in to follow this  
Followers 0