- Joined
- Dec 26, 2013
- Messages
- 1,633
- Solutions
- 11
- Reaction score
- 877
Greetings otland,
I have recently started playing with creation of my own classes and subclasses and seem to have ran into a problem. I don't know how to make my class a subclass of an already predefined (in the source) class. Example of what I mean is say I want to create a new class called Summon, and I want the summon class to have all the properties of the class Monster, which is already defined in our source code.
I already have working classes, but I can't figure out how to make them inherit the properties from a predefined class.
For some reason (I assume it's because I am not creating the object correctly), I can't make my new class actually execute an action outside of the construction. What I mean is like this, first create the class, then constructor, then function for the summon class
This causes my server to crash.
Even trying it like this
causes a crash.
Could someone please show me the proper way to create a sub-class of an already predefined class, because when I create the object, for some reason the object doesn't inherit, and if I try passing the object itself in the class's properties like this :
When trying to call that object to execute like this:
All ways crash my server, but if I tried to check it like this
It will print! Add the execution of creature:say(text, type) and it crashes still, no print.
Few people I know are good with lua, sorry for tagging you guys again, but I really am at a stopping point because of this.
@Limos @Ninja @Printer @Flatlander @Evil Hero @forgee @Evan
I have recently started playing with creation of my own classes and subclasses and seem to have ran into a problem. I don't know how to make my class a subclass of an already predefined (in the source) class. Example of what I mean is say I want to create a new class called Summon, and I want the summon class to have all the properties of the class Monster, which is already defined in our source code.
I already have working classes, but I can't figure out how to make them inherit the properties from a predefined class.
For some reason (I assume it's because I am not creating the object correctly), I can't make my new class actually execute an action outside of the construction. What I mean is like this, first create the class, then constructor, then function for the summon class
Code:
function Summon:say(text, type)
return self:say(text, type)
end
Even trying it like this
Code:
function Summon:say(text, type)
local creature = Creature(self.cid) --- this is properly saved in summon class constructor
return creature:say:(text, type)
end
Could someone please show me the proper way to create a sub-class of an already predefined class, because when I create the object, for some reason the object doesn't inherit, and if I try passing the object itself in the class's properties like this :
Code:
self.creature = Creature(param)
When trying to call that object to execute like this:
Code:
function Summon:say(text, type)
return self.creature:say(text, type)
end
All ways crash my server, but if I tried to check it like this
Code:
function Summon:say(text, type)
local creature = Creature(self.cid)
if creature then
print("Yup it passes")
end
end
It will print! Add the execution of creature:say(text, type) and it crashes still, no print.
Few people I know are good with lua, sorry for tagging you guys again, but I really am at a stopping point because of this.
@Limos @Ninja @Printer @Flatlander @Evil Hero @forgee @Evan