Papyrus Common Pitfalls and Best Practices
Revision as of 13:44, 10 February 2012 by imported>Jimhsu (→Cannot create new object)
Introduction
This is a page for the community to document common pitfalls, mistakes, and best practices when working with Papyrus. Links are strongly encouraged here as so are code fragments to demonstrate what you're talking about.
General format:
- Title of problem (make this a heading)
- Description of problem
- Explanation
- Solution (if any)
General
Object Handling
Cannot create new object
- Problem: I can't create a new object.
- Explanation: Papyrus currently does not support the instantiation of objects within script; the new keyword only works for arrays, not objects (unlike Java, for example), and constructors do not seem to work.
- Solution: For a workaround, you could try casting a PlaceAtMe ObjectReference as your desired object. Of course your object must extend ObjectReference for this to work.
Can't cast an object as its child
- Problem: I can't cast an object as its child. For instance, casting an ObjectReference as a TestReference when TestReference extends ObjectReference.
- Explanation: Casting will only work if the reference casted actually has its script attached. For instance, the TestReference base object needs to have the TestReference script attached in the editor form window for it to be castable from ObjectReference to TestReference.
- Solution: Use the editor and attach the script to the object you're actually casting. For instance, if TestReference is supposed to refer to a book, open up the book you want to cast in the editor window, goto the scripts section, and attach the TestReference script from there.