PÄSSION ~ Mixins and subclasses questions
Posted: Wed Dec 16, 2009 1:03 am
i've attached my "game". run it and check out stdout.txt to see the results (nothing "visual". it just output's some text).
a_dog's describe variable works well. i have a bit of a problem with checking to see if it can fly though. the mammal class has fly and canFly functions. canFly just returns 0, and fly prints "I've no wings, I can't fly!". i then include the hasWings module to the class and that 'overwrites' (?) the 2 functions with it's own ones (the new canFly returns 1 (true) and fly returns 'flap flap flap!'. i don't know if this is the right way to do it. the reason i have the 2 fly and canFly functions in the mammal class in the first place is because i have no other way of checking to see if it can fly or not.
secondly, what i tried to do was create a subclass for mammal called dog. dog can just be empty if i needed but it was there so that when i did local dog1 = dog:new(...) i knew i was getting a dog. i could then make other subclasses for mammal, like "bat" which would inclue "hasWings". the problem here is when i make an empty subclass "dog", and call the function describe, it doesnt exist. do i need to re-write all the functions in dog and call super(self,...)? that'd work, but it just seems like alot of re-writing for nothing.
a_dog's describe variable works well. i have a bit of a problem with checking to see if it can fly though. the mammal class has fly and canFly functions. canFly just returns 0, and fly prints "I've no wings, I can't fly!". i then include the hasWings module to the class and that 'overwrites' (?) the 2 functions with it's own ones (the new canFly returns 1 (true) and fly returns 'flap flap flap!'. i don't know if this is the right way to do it. the reason i have the 2 fly and canFly functions in the mammal class in the first place is because i have no other way of checking to see if it can fly or not.
secondly, what i tried to do was create a subclass for mammal called dog. dog can just be empty if i needed but it was there so that when i did local dog1 = dog:new(...) i knew i was getting a dog. i could then make other subclasses for mammal, like "bat" which would inclue "hasWings". the problem here is when i make an empty subclass "dog", and call the function describe, it doesnt exist. do i need to re-write all the functions in dog and call super(self,...)? that'd work, but it just seems like alot of re-writing for nothing.