SCLeo Posted October 7, 2020 Share Posted October 7, 2020 Hello, I just got started modding Skyrim. Currently, I am quite confused as to how scripts work with forms. For example, if there is a script which takes a property and has a local variable. There are also 2 new helmet types A and B. I then assign script S to both A and B. Does that duplicate my script? Or in other words, does that mean I will have two instances of that local variable and two instance of that property? Also, when I create multiple copies of A in game, will that duplicate scripts as well? Or all actual in game instances of A share the same script? Thanks. Link to comment Share on other sites More sharing options...
dylbill Posted October 7, 2020 Share Posted October 7, 2020 If your script extends ObjectReference, each instance will have its own local variables. If your script extends armor or objectreference, and you attach it to two helmets in the creation kit, you can assign different values to the properties for each, so they are seperate. Generic vanilla scripts are used multiple times with different property values a lot. Link to comment Share on other sites More sharing options...
Reneer Posted October 7, 2020 Share Posted October 7, 2020 For example, if there is a script which takes a property and has a local variable. There are also 2 new helmet types A and B. I then assign script S to both A and B. Does that duplicate my script? Or in other words, does that mean I will have two instances of that local variable and two instance of that property?Papyrus is a threaded scripting language. I've found that, for me at least, thinking about the relationship between game objects and scripts makes more sense when you apply object-oriented programming logic to it. Which makes sense because that is basically what Papyrus is, just without some of the fancier lower-level object creation that would make my day. What I would give to have a (vanilla, sorry SKSE team) function to actually get a FormID past 7F FF FF FF in Papyrus. Maybe I'll get my wish in Starfield. To answer your questions, your script would not be duplicated, each individual helmet created of types A and B would have its own instance of properties and variables. Please note that this is my understanding and I could be a little bit off base on some things, it's been a while since I did research on the inner workings of Papyrus. Also, when I create multiple copies of A in game, will that duplicate scripts as well? Or all actual in game instances of A share the same script?They all share the same script but will have individual instance / object data. Here is a link to the Papyrus Introduction on the Skyrim Creation Kit Wiki. Link to comment Share on other sites More sharing options...
SCLeo Posted October 7, 2020 Author Share Posted October 7, 2020 If your script extends ObjectReference, each instance will have its own local variables. If your script extends armor or objectreference, and you attach it to two helmets in the creation kit, you can assign different values to the properties for each, so they are seperate. Generic vanilla scripts are used multiple times with different property values a lot. For example, if there is a script which takes a property and has a local variable. There are also 2 new helmet types A and B. I then assign script S to both A and B. Does that duplicate my script? Or in other words, does that mean I will have two instances of that local variable and two instance of that property?Papyrus is a threaded scripting language. I've found that, for me at least, thinking about the relationship between game objects and scripts makes more sense when you apply object-oriented programming logic to it. Which makes sense because that is basically what Papyrus is, just without some of the fancier lower-level object creation that would make my day. What I would give to have a (vanilla, sorry SKSE team) function to actually get a FormID past 7F FF FF FF in Papyrus. Maybe I'll get my wish in Starfield. To answer your questions, your script would not be duplicated, each individual helmet created of types A and B would have its own instance of properties and variables. Please note that this is my understanding and I could be a little bit off base on some things, it's been a while since I did research on the inner workings of Papyrus. Also, when I create multiple copies of A in game, will that duplicate scripts as well? Or all actual in game instances of A share the same script?They all share the same script but will have individual instance / object data. Here is a link to the Papyrus Introduction on the Skyrim Creation Kit Wiki. Ah thank you. I think that cleared a lot of confusion I had. One more question, if the variables/properties are created for each instance of helmet in game, how does it handle items stacking? For example, if I have a helmet with a local variable foo=1 in its attached script lying on the ground and a helmet with a local variable foo=2 in its attach script in the inventory, when I pick up the helmet on the ground, what will happen? Does the game secretly track that you have the same helmet but with different local variables in your inventory? Link to comment Share on other sites More sharing options...
dylbill Posted October 7, 2020 Share Posted October 7, 2020 (edited) I wasn't sure about this, so I did a test, and yes the game will track that you have 2 helmets with different variables on them. Here's the script I used to test: Scriptname TestModObjectRef extends ObjectReference Int Property TestInt Auto GlobalVariable Property TestModGv Auto Event OnInit() TestInt = TestModGv.GetValueInt() EndEvent Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) Debug.Notification("TestInt = " + TestInt) EndeventI changed the globalvariable between creating the helmet instances, and they retained their different TestInts when entering and leaving the inventory. Edited October 7, 2020 by dylbill Link to comment Share on other sites More sharing options...
SCLeo Posted October 7, 2020 Author Share Posted October 7, 2020 I wasn't sure about this, so I did a test, and yes the game will track that you have 2 helmets with different variables on them. Here's the script I used to test: Scriptname TestModObjectRef extends ObjectReference Int Property TestInt Auto GlobalVariable Property TestModGv Auto Event OnInit() TestInt = TestModGv.GetValueInt() EndEvent Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) Debug.Notification("TestInt = " + TestInt) EndeventI changed the globalvariable between creating the helmet instances, and they retained their different TestInts when entering and leaving the inventory. Ah, I see. Thank you for letting me know how it works. Link to comment Share on other sites More sharing options...
NexusComa2 Posted October 7, 2020 Share Posted October 7, 2020 (edited) When you look at an item in the creation kit let's say a helmet. If you double click on it from the object window a type of form will popup (edit: you need to drop the item in the game to see the form with the base button). Within that you will see a button to get to the items base. The base is the real object/item The form that held the base button can be changed or customized. Scripts can be added if you wish. That will make the item a custom game item. It also will never interfere with the real game item at its base. So the item isn't unique unless you change that form. Any changes to the item should all be done from that form. You always leave the base untouched. If you are working with items already in the game. Globals are game variables that are created to work with scripts. They are not apart of the item form or it's base. They are used in the scripts. So you can have/add any globals you wish. They are not directly connected to any item unless being used in a script from that item. If you have two different globals and change them they will indeed remain what you changed them to -- unless a script changed them again.Is there a script on each item ... yes ... kind of. There is a reference to use a script that is a part of the form or base. 1000 items could use the same script. None of them will actually contain the script literally. But they will all have a reference within them to use that one script. Edited October 7, 2020 by NexusComa2 Link to comment Share on other sites More sharing options...
dylbill Posted October 7, 2020 Share Posted October 7, 2020 (edited) I should have specified, I duplicated the elven helmet and I put that script on the helmet. In game, I used the PlaceAtMe console command to place one instance of the helmet in the world. The TestInt was set to 0. Then I used the console command Set TestModGv to 4. I placed another instance of the helmet with placeAtMe. Its TestInt was set to 4. I picked up both helmets and dropped them again, and the debug.notification showed that one helmet retained the testInt as 0, and the other retained the TestInt as 4. So the two seperate object references do store different data even though they are using the same script. Edited October 7, 2020 by dylbill Link to comment Share on other sites More sharing options...
NexusComa2 Posted October 8, 2020 Share Posted October 8, 2020 Yes because they both have different global variables setup for them. Find the base file for the helm ... Duplicate it, rename it, then make your new helm from that base file. Now your helm has nothing to do with any other helm in Skyrim. It's is unique ... mod will require a .bsa now. Link to comment Share on other sites More sharing options...
dylbill Posted October 8, 2020 Share Posted October 8, 2020 No, its the same global variable. The point being is that the TestInt can save different values on different object references, with the same inherited script. To put it another way, If the script extends object reference, and Is attached to a base form, each instance of that form can hold different values of the same properties. Link to comment Share on other sites More sharing options...
Recommended Posts