Who wants to hear me bitch about Papyrus some more?
Papyrus is object-oriented and features inheritance. When you attach a script to an ObjectReference (the script object that represents instances of objects in the world), you actually extend the ObjectReference - your script becomes a new object type that is derived from the ObjectReference script. You can then cast ObjectReferences to your script type in other scripts, or declare variables of your script type, much like in any object-oriented language.
However, I just tried to compile a script which contained a function that takes a ReferenceAlias type argument. It is used by two other functions, each of which call it with a different script type that is derived from ReferenceAlias
[code]Function myFunction(ReferenceAlias arg)
;does fun stuff
endFunction
Function foo()
;does fun stuff
myScriptA var1 ;myScriptA extends ReferenceAlias
myFunction(var1)
endFunction
Function bar()
;does more fun stuff
myScriptB var2 ;myScriptB also extends ReferenceAlias
myFunction(var2)
endFunction[/code]
And the papyrus compiler has given me these errors:
code: type mismatch on parameter 1 (did you forget a cast?)
(141,4): type mismatch on parameter 1 (did you forget a cast?)[/code]
That’s right. In papyrus, you have to cast derived objects to their parent type in order to pass them as arguments. I’m actually gaining a great appreciation for papyrus as a tool for extending the Skyrim engine, but this behavior is all kinds of retarded.
EDIT: And now it’s telling that I can’t cast them to ReferenceAliases because the “types are incompatible.” Even though they’re derived from ReferenceAliases. What does it want from me? Is it going to make me write two different functions that do the same thing, but one with myScriptA and one with myScriptB?