Class System for "entities"
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Class System for "entities"
My entities are just a table in another table (entst), I want entities to have a "base class" which would have methods like ent:Create() etc. then I could create subclasses, and I could set an entity's "class" in their basic table which would inherit all functions and variables from the class and it's superclasses. I tried to do this with tables and failed.
while true do end;
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Class System for "entities"
You know google can usually help with general questions like this. I'm sure googling "how to do classes and inheritance in lua" would return useful results
- CaptainMaelstrom
- Party member
- Posts: 161
- Joined: Sat Jan 05, 2013 10:38 pm
Re: Class System for "entities"
Yeah, check out middleclass, 30log, or any of the other oop libraries floating around. Or if you want to make one yourself, check out the PiL:
http://www.lua.org/pil/
It has a whole chapter on OOP in lua:
http://www.lua.org/pil/16.html
http://www.lua.org/pil/
It has a whole chapter on OOP in lua:
http://www.lua.org/pil/16.html
Re: Class System for "entities"
To do this you would need to use metatables.
In particular this explains set by set how to do it. Don't worry it is not as hard as it might seem at its face.
http://lua-users.org/wiki/ObjectOrientationTutorial
In particular this explains set by set how to do it. Don't worry it is not as hard as it might seem at its face.
http://lua-users.org/wiki/ObjectOrientationTutorial
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
Who is online
Users browsing this forum: No registered users and 1 guest