Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Create New Form Instance in Script


jaxonz
 Share

Recommended Posts

I guess perhaps I don't understand Papyrus as well as I had thought.

 

I've created a new class that extends ObjectReference. In another script, I would like to instantiate a new instance of my class. I thought I could just use something like:

MyExtendedClass objMyClass = new MyExtendedClass

However, the compiler chokes on this as it assumes I'm trying to use the New keyword to instantiate an array.

 

Hoping this is a simple syntax issue and not that Papyrus fundamentally prohibits generation of new script objects.

Link to comment
Share on other sites

No, I'm afraid it isn't a simple syntax issue, if I understand what you're trying to do. Excuse me if any of the following is too elementary for you. No slight or insult is intended.

 

We can't create our script objects out of thin air by just referring to the script, as you seem to be attempting. We can only create objects that have been pre-defined in the Object Window of the CK with a base form ID. When we instantiate one of these forms in the game world, say by dragging a basket from the Object Window to the Render Window, we create a copy that is an instance of one of the native script types, such as ObjectReference in the case of a basket.

 

If we wish to create an object that has extensions to its native type, we must add a base form ID of that type to the Object Window and then add our extension scripts as properties of that form. So, for example, we might whip up a model of a snark in a 3D modeling program, create a Static form that points to that model in the Object Window, and then add a script named Snark that extends ObjectReference in the data window for that form.

 

We can then create copies of our snark object in the game world either at design time (drag-and-drop in the CK) or at run time through another script, which seems to be your goal here. Run-time instantiation can be done in two ways. One uses the PlaceAtMe function, which creates one or more copies of a given form at a given location. The location may be the player or may be some other target, such as a marker or another object. The second method is to place copies directly into the inventory of a player or container using AddItem.

 

The second, instantiating script must also be attached to a base form. This form may be a trigger area or other activator placed at design time, so your object will appear when a character walks into a trap or pulls a lever. For example, see the Papyrus Basics tutorial here that adds gold to your inventory when a button is pressed. Or the form may be a Magic Effect that causes your object to be summoned. Or it might be something else, such as a quest stage.

 

If your second script also needs to communicate with your object script -- to check or set properties, call functions, or trigger methods in MyExtendedClass or its parent ObjectReference -- then you're getting into slightly deeper waters. If this is the case, I would modestly suggest checking out the tutorial on Simple Inter-script Communication. This tutorial covers the basics of getting a handle on an object so that you can work with its scripts.

 

Hope this helps.

Edited by BrettM
Link to comment
Share on other sites

Thanks for your informative and very respectful response. In this case, decades of OO programming is working to my disadvantage. I get frequent reminders about just how weak, buggy, and poorly documented Papyrus is... this is just another one. But there are many ways to skin cats!

 

This is related to another of my posts in this forum. I'm trying to avoid spaghetti code in my Positioner mod to allow in-game movement of mannequins, weapon racks, interactive bookshelves, etc. These are all actually collections of objects (typically an Activator, a Static, and sometimes a Marker). What I've created is a class that holds references to the related parts and implements ObjectReference functions such as TranslateTo to manage and hide the complexity of moving all those objects in a coordinated fashion. If I could instantiate such classes it would allow easy manipulation of any number of these types of collections.

 

I understand now that no "objects" can exist in Papyrus which do not have some corresponding object created in the CK. (I've seen other threads discussing handshaking between Papyrus and the game engine which allude to this as well.)

 

Rather than create an object in CK to hold my script, I think perhaps the best way to address this is to use a ReferenceAlias to point to the game object which has the physical model (e.g., the the PlayerHouseMannequin Actor in the case of mannequins) and dynamically attach a script that tracks the other objects and overrides the functions I care about. (I realize that this does, in effect create a CK object; not trying to split hairs here; just trying to say that PlaceAtMe or AddItem won't be helpful in this case.)

Link to comment
Share on other sites

Ah. I haven't had time lately to follow the scripting threads as closely as usual, but now I understand what level you're operating on. I did have the feeling that you might be tripping over your experience with real programming here, as I think most of us programmers do from time to time when dealing with the feeble thing that is Papyrus.

 

One of the flaws of Papyrus is that it doesn't give you access to all of the data for an object. For example, you can't set the Model field or the intensity of a light via script, but can only do this in the CK. Thus, the CK must be used to pre-define all of the information that Papyrus can't touch, preventing you from instantiating anything free of CK connections.

 

I am aware of a method for using the console to move a mannequin, but it requires the use of the CK to look up the RefIDs for the invisible bits, after which you can move the marker, physical model, etc. a piece at a time. If you can gather all the information with a script, that would be fantastic.

 

I've not yet worked with aliases and dynamic attachment of scripts, so perhaps you've hit on a workable approach. I certainly hope so, because the generic ability to move functional collections such as mannequins at run time has been a holy grail for a lot of us. (Being able to instantiate them with a simple PlaceAtMe would be even more of a boon to console decorators, but I will settle for the ability to move them around. That would at least allow one to set up a warehouse cell from which pre-defined collections could be moved.)

 

Good luck with the project!

Link to comment
Share on other sites

Thanks Brett,

 

I have the movement of mannequins already working today in my Positioner mod. What I'm trying to do is extend that capability without ending up with very complex code.

http://www.nexusmods.com/skyrim/mods/52583

 

Someone else made a sort of warehouse companion mod where one can get furniture without stealing if from other locations.

http://www.nexusmods.com/skyrim/mods/53813

 

And, although I haven't tried them yet, it seems that at least a couple mod allow the dynamic creation and movement of mannequins.

http://www.nexusmods.com/skyrim/mods/10578/

http://www.nexusmods.com/skyrim/mods/8635/

Edited by jaxonz
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...