LegoManIAm94 Posted March 21, 2019 Share Posted March 21, 2019 I made this simple script but I am unsure if it will cause any saved games to bloat when it is executed multiple times. I plan on adding this script to objects that can be only obtainable by using the forge by crafting them into the game. Essentially when the player crafts this item it will run the script. The player will never see this in a cell, in a container, in a NPC or be purchase-able in barter. When this item is crafted it will be removed when the script is ran. If you have any other suggestions I am open to hear them. Scriptname myScript extends ObjectReference GlobalVariable Property myGlobal Auto MiscObject Property myConstructibleObject Auto Int Property myConstructibleObjectCount = 1 Auto Event OnInIt() myGlobal.SetValue(myGlobal.GetValue() + 1) Game.GetPlayer().AddItem(myConstructibleObject, myConstructibleObjectCount) Game.GetPlayer().RemoveItem(self, myConstructibleObjectCount) EndEvent Link to comment Share on other sites More sharing options...
ReDragon2013 Posted March 21, 2019 Share Posted March 21, 2019 (edited) Whether your script will cause bloated save games or not, you have to test on your own Skyrim installation.Use Hadorams "Save cleaner" to control the amount of script instances (especially for your scripts). I would code like this, no idea is better or avoid bloat. I also changed the script name, myScript is not really useful. lmaConstructionScript Scriptname lmaConstructionScript extends ObjectReference {purpose of this script ??} ; "I plan on adding this script to objects that can be only obtainable by using the forge by crafting them into the game." ; https://forums.nexusmods.com/index.php?/topic/7499266-would-this-script-causing-saved-game-to-be-bloated/ ; LegoManIAm94 wrote: "I am unsure if it will cause any saved games to bloat" GlobalVariable PROPERTY myGlobal auto ; your new created globalVar MiscObject PROPERTY myConstructibleObject auto ; the object to be constructed Int PROPERTY myConstructibleObjectCount = 1 auto ; the amount of objects [default=1] ; -- EVENTs -- 2 EVENT OnInit() RegisterForSingleUpdateGameTime(0.0) ; do not overwhelming the init event ENDEVENT EVENT OnUpdateGameTime() actor player = Game.GetPlayer() IF (myConstructibleObjectCount > 0) player.AddItem(myConstructibleObject as Form, myConstructibleObjectCount) player.RemoveItem(self as Form, myConstructibleObjectCount) myGlobal.Mod(1) ;;; self.Delete() ; <-- maybe this is also needed ENDIF ENDEVENT Edited March 21, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
LegoManIAm94 Posted March 22, 2019 Author Share Posted March 22, 2019 I did downloaded it and made a save never crafting any of these items. Then I made a save after crafted a dozen of the items, then I made a third save crafting about 50 of the items. I did find the more of these items I crafted the more script instances there were of the script that is attached to the object. So I image if I crafted 1000, 10000 of these items it can cause bloating and this mod I am working on is a crafting mod designed for the user to craft items thousands of times. If a user's saved game had 1 million script instances does that bloat the game making the saved game file run slow or will it just make the saved game file size large and have lots of data in the saved game that will never render and be "useless"? Link to comment Share on other sites More sharing options...
maxarturo Posted March 22, 2019 Share Posted March 22, 2019 (edited) The sure thing is that the more script instances the save file has > the more heavy in size it gets > that has the consequence of longer and longer loading times as the save file keeps growing.This can be very frustrating if you have like 250 mods installed or more, you might end up needing 45 minutes to load a save or more. * i've encountered this in the past with a mod (won't name it for obvious reasons), after two days of playing (approximately 8 hours) my save file grow in size from 54mb to 210mb !!, and end up needing close to an hour to load a save. Edited March 22, 2019 by maxarturo Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 22, 2019 Share Posted March 22, 2019 You have an item that can only be crafted. When crafted and the object becomes viable it is placed in the player inventory where you intend to increase a global variable, add a item and then remove that same item. Why the whole add and remove? Seems pointless. Also, it is better to Mod the global variable than it is to get and set. This is especially true when more than one instance of a script could be trying to manipulate the global variable at the same time. I'm wondering if you wouldn't be better off using a script on a player alias on a quest dedicated to your mod. A single script listening for the item in question being added seems far better than as many script instances as there are instances of the object in question. Link to comment Share on other sites More sharing options...
LegoManIAm94 Posted March 22, 2019 Author Share Posted March 22, 2019 You have an item that can only be crafted. When crafted and the object becomes viable it is placed in the player inventory where you intend to increase a global variable, add a item and then remove that same item. Why the whole add and remove? Seems pointless. Also, it is better to Mod the global variable than it is to get and set. This is especially true when more than one instance of a script could be trying to manipulate the global variable at the same time. I'm wondering if you wouldn't be better off using a script on a player alias on a quest dedicated to your mod. A single script listening for the item in question being added seems far better than as many script instances as there are instances of the object in question. How will I go about making a script to listen when an item is added to the player. I tried to create a script that does that with OnItemAdd even. Link to comment Share on other sites More sharing options...
LegoManIAm94 Posted March 22, 2019 Author Share Posted March 22, 2019 Scriptname myScript extends Quest GlobalVariable Property myGlobal Auto Keyword Property myKeyword Auto Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akFormReference, ObjectReference akSourceContainer) If akBaseItem.HasKeyword(myKeyword) myGlobal.SetValue(myGlobal.GetValue() + 1) EndIf EndEvent This is my attempt with a quest script to detect when the player crafts a certain item. But I have had no luck with the function executing. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 22, 2019 Share Posted March 22, 2019 The script needs to extend ReferenceAlias rather than Quest. Also make sure that the script is attached to a reference alias record on a quest.Ignore, for now, the rest of this tutorial. All you need to know is the specific linked subsection regarding setting up a reference alias.https://www.creationkit.com/index.php?title=Dynamically_Attaching_Scripts#Set_Up_a_Reference_Alias Link to comment Share on other sites More sharing options...
LegoManIAm94 Posted March 22, 2019 Author Share Posted March 22, 2019 The script needs to extend ReferenceAlias rather than Quest. Also make sure that the script is attached to a reference alias record on a quest.Ignore, for now, the rest of this tutorial. All you need to know is the specific linked subsection regarding setting up a reference alias.https://www.creationkit.com/index.php?title=Dynamically_Attaching_Scripts#Set_Up_a_Reference_Alias That does work! Thank you. I would of never thought of that. Link to comment Share on other sites More sharing options...
Recommended Posts