DocClox Posted April 17, 2021 Share Posted April 17, 2021 I'm making holotapes to hold programs to drive a programmable tattoo machine. I have an object reference that points at a record that's a subclass of a subclass of ObjectReference. But when I try and cast the ObjectReference to the intermediate class, it yields None Base class that inherits from ObjectReference: Scriptname rrs:holo_tattoo_base extends ObjectReference And I have a subclass of that which implements a specific program Scriptname rrs:holo_tattoo_raider_qr extends rrs:holo_tattoo_base And I have a holotape that uses the rrs:holo_tattoo_raider_qr script. https://imgur.com/a/r6YFVI0 I place an instance objectreference ref = trolley.placeatnode("holotape_node", default_program) debug.messagebox("reference = " + ref.getDisplayName())GetDisplayName() correctly shows the name of the tape. So the reference is right. But when I take a variable of type rrs:holo_tattoo_base programAnd try and cast to if from the ref I just placed program = ref as rrs:holo_tattoo_base debug.messagebox("program = " + program) I get None back. Anyone know what is going on? As I understand the language, this ought to work. Am I missing the obvious somewhere? Link to comment Share on other sites More sharing options...
niston Posted April 17, 2021 Share Posted April 17, 2021 Try: (ref as ObjectReference) as rss:holo_tattoo_base Link to comment Share on other sites More sharing options...
DocClox Posted April 18, 2021 Author Share Posted April 18, 2021 Nope. Not having it. What does work is casting it to rrs:holo_tattoo_raider_qr which is the leaf of the subclass chain. However, doing that defeats the whole point of the object oriented paradigm. I don't want to have to know what the specific tape instance is. This is starting to look like a compiler bug. I guess I'll have to script everything as holo_base and populate the struct arrays in the CK properties window. Ugh! Link to comment Share on other sites More sharing options...
niston Posted April 18, 2021 Share Posted April 18, 2021 OOP is weird in Papyrus.I came across something similar a while ago, where casting a derived class to it's parent class and then calling functions on that would still call said functions on the derived class. *shrug* Something that's nice for a little change: You can implement "fake polymorphism" by simply attaching several scripts to something and then casting that objectref as the respective script. I find this useful to build modular systems, where some script implements an aspect that can be shared among/used by several other scripts. Link to comment Share on other sites More sharing options...
DocClox Posted April 18, 2021 Author Share Posted April 18, 2021 Something that's nice for a little change: You can implement "fake polymorphism" by simply attaching several scripts to something and then casting that objectref as the respective script.Yeah. That could work. Have the array of instructions and the builder and access functions in one script, and the one to populate the array on the other. Have to use OnInit() to call the setup function... possible race conditions, but should be OK if I don't set any initializers... on the base... I'll try that. That sounds like it should do what I want. Link to comment Share on other sites More sharing options...
DocClox Posted April 19, 2021 Author Share Posted April 19, 2021 OK, that worked. I had to use OnLoad to get it to initialize for some reason, so it'll need a 3d instance at some point, but that can be managed. Maybe I can suspend the tape in a ball of green energy for a few seconds when it's first added to the machine, just to make sure it had a 3d instance at some point. Other than that, fantastic. Good call. Link to comment Share on other sites More sharing options...
Recommended Posts