HerrBaron Posted March 13, 2012 Share Posted March 13, 2012 I have a quest with the following script attached: Scriptname ADVTentQuestScript extends Quest Import ADVObjectWithChildren SPELL Property SummonTentSpellRef Auto Message Property SpellAddedMessage Auto String Property ADVLogName Auto ObjectReference Property rTent Auto Keyword[] Property kwChildren Auto ADVObjectWithChildren m_rTentShell ADVObjectWithChildren Property TentShell ADVObjectWithChildren Function Get() return m_rTentShell EndFunction EndProperty Event OnInit() Debug.OpenUserLog( ADVLogName ) Debug.TraceUser ( ADVLogName, "Entering ADVTentQuestScript.OnInit" ) Debug.Notification ( "Entering ADVTentQuestScript.OnInit" ) if ( !game.GetPlayer().HasSpell( SummonTentSpellRef ) ) Debug.TraceUser (ADVLogName, "Adding Spell.") game.GetPlayer().AddSpell( SummonTentSpellRef ) SpellAddedMessage.Show() m_rTentShell = rTent As ADVObjectWithChildren m_rTentShell.Initialize( kwChildren ) endif Debug.TraceUser ( ADVLogName, "Leaving ADVTentQuestScript.OnInit" ) Debug.Notification ( "Leaving ADVTentQuestScript.OnInit" ) EndEvent On line 8, m_rTentShell is a script which extends ObjectReference; it looks like this (not complete): ScriptName ADVObjectWithChildren Extends ObjectReference Import AdvLinkedChildObject Quest m_Quest = None Bool Function MoveChildren() return( False ) EndFunction Bool Function Initialize( Keyword[] kwChildren ) Debug.Notification ("Entering ADVObjectWithChildren.Initialize") int iChildren = kwChildren.Length Debug.Notification ("We have " + iChildren + "children.") ; Debug.TraceUser( ADVTentQuest.ADVLogName, "ADVObjectWithChildren.Initialize; we have " \ ; + iChildren + "children.") Debug.Notification ("Leaving ADVObjectWithChildren.Initialize") return( True ) EndFunction Note that these lines in the quest script above: m_rTentShell = rTent As ADVObjectWithChildren m_rTentShell.Initialize( kwChildren ) are telling me respectively at runtime that Papyrus can't assign to a None object, and that it can't call initialize on it. So my question is this: why is the cast "rTent as ADVObjectWithChildren" not working? Any assistance you guys can give me on this will be greatly appreciated! -HB Link to comment Share on other sites More sharing options...
fg109 Posted March 13, 2012 Share Posted March 13, 2012 By runtime, you mean that it compiled fine but that it didn't work in the game, right? Does the object reference you put in for rTent have your second script (ADVObjectWithChildren) attached to it? Link to comment Share on other sites More sharing options...
HerrBaron Posted March 13, 2012 Author Share Posted March 13, 2012 By runtime, you mean that it compiled fine but that it didn't work in the game, right? Does the object reference you put in for rTent have your second script (ADVObjectWithChildren) attached to it? Many thanks for the reply! :) Yes; it compiles, and runs, adds the spell, then I get the aforementioned error messages. No, I haven't attached the second script to the reference; is this necessary? I thought we were able to use the object-oriented principle of polymorphism with Papyrus...? In other words, I should be able to assign a pointer of type parent to a pointer to type child, right? E.G. with Animal->Horse, Horse is an animal; I should be able to assign a Horse to Animal, and have access to the methods of Animal. Best!-HB Link to comment Share on other sites More sharing options...
fg109 Posted March 13, 2012 Share Posted March 13, 2012 No I really do think you need to have the script attached to the object. I'm trying to think of a good analogy but I suck. :facepalm: Link to comment Share on other sites More sharing options...
HerrBaron Posted March 13, 2012 Author Share Posted March 13, 2012 No I really do think you need to have the script attached to the object. I'm trying to think of a good analogy but I suck. :facepalm: http://forums.nexusmods.com/public/style_emoticons/dark/biggrin.gif No, you don't suck; thank you for helping out! I'll give it a shot and let you know. Link to comment Share on other sites More sharing options...
jimhsu Posted March 13, 2012 Share Posted March 13, 2012 (edited) Discussed here: http://www.creationkit.com/FAQ:_My_Script_Doesn%27t_Work!#Can.27t_cast_an_object_as_its_child ("Can't cast an object as its child") There's a reason why I wrote most of that page. No offense, but the OOP implementation in Papyrus is a fairly primitive one (by C++/Java standards). Casts have to be strict. No array casts. No multiple inheritance. No templates or interfaces or abstract classes. You can't even instantiate objects for god's sake (which rules out constructors, destructors, supers, etc). Edited March 13, 2012 by jimhsu Link to comment Share on other sites More sharing options...
HerrBaron Posted March 13, 2012 Author Share Posted March 13, 2012 Discussed here: http://www.creationk...ct_as_its_child ("Can't cast an object as its child") There's a reason why I wrote most of that page. No offense, but the OOP implementation in Papyrus is a fairly primitive one (by C++/Java standards). Casts have to be strict. No array casts. No multiple inheritance. No templates or interfaces or abstract classes. You can't even instantiate objects for god's sake (which rules out constructors, destructors, supers, etc). it works; dude, you're a god, and I am not worthy! :D All true to the above, too; primitive is the appropriate word. Instantiation of a ADVObjectWithChildren would have been simple, if we could simply do a "m_rTentShell = new ADVObjectWithChildren( rTent)", but nooooooooo! Thank you jimhsu! Much appreciated! -HB Link to comment Share on other sites More sharing options...
Recommended Posts