Excpetionally simple question about inheritence...
You'll have to forgive what Im sure is a very simple question, but this is the first time I've really delved into scripting properly. Anyway - how exactly do you make a structure a child of another structure and have it inherit the properties and methods of the parent in Maxscript?
The only example I have been able to find is from an old topic on CGTalk from about 4 years ago. It gives this code as a simple example to demonstrate:
struct baseClass
(
fn function1=
(
print "function1"
)
)
struct mediumClass
(
base=baseClass(), --this an instance of the base object
function1=base.function1, --this is the actual inheritance, so we take over this function from baseclass.
fn function2=fn
(
print "function"
)
)
...and you would then use the listener to create an instance of mediumClass and test to see if it had inherited the functions.
However, evaluating this throws up errors. Can anyone provide a very simple example to demonstrate how to achieve inheritence?
Cheers.
Comments
Ah yeah, I see, I assumed
Ah yeah, I see, I assumed the 'base' word was some sort of command for defining inheritence, but it was just trying to create a new variable and set it to the other class.
So strictly speaking, is that second example actually inheritence? I'm under the impression that if something is a child of another class, it has all the properties of that class, plus any new ones you define in the child class. But that is being specifically told to copy a function, and only works if the instance is declared with the baseclass. But the class itself isn't strictly a child in the OoP sense of classes?
struct baseClass ( fn
The biggest problem you had is that you are trying to define what the variables hold in the STRUCT definition, and this should be done when creating an instance of the class. There also seemed to be an extra "fn" on the function2 definition, which is probably what was causing the error for you.