Inte Posted October 26, 2015 Posted October 26, 2015 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 Quest Import Game iDDeUtilities Property iDDeUtil Auto FORM[] Property iDDeBlindFold Auto Hidden ;BlindFold ;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb Function 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 EndIf EndFunction ;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 Quest Import Game iDDeUtilities Property iDDeUtil Auto ;BlindFold ;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb Form 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 Eqp EndFunction ;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb Here to get the same red Ebonite blindfold I would call it like so,iDDeGetBlindFold(Slave, 13) So ... which would be faster?
bjornk Posted October 26, 2015 Posted October 26, 2015 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.
Inte Posted October 26, 2015 Author Posted October 26, 2015 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?
bjornk Posted October 26, 2015 Posted October 26, 2015 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.
Inte Posted October 26, 2015 Author Posted October 26, 2015 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.
bjornk Posted October 26, 2015 Posted October 26, 2015 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.
Inte Posted October 27, 2015 Author Posted October 27, 2015 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
Guest Posted October 27, 2015 Posted October 27, 2015 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.
Inte Posted October 27, 2015 Author Posted October 27, 2015 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.
Guest Posted October 27, 2015 Posted October 27, 2015 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.
bjornk Posted October 27, 2015 Posted October 27, 2015 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.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.