Class System for "entities"

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
RonanZero
Citizen
Posts: 90
Joined: Mon Oct 20, 2014 3:33 am

Class System for "entities"

Post by RonanZero »

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;
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Class System for "entities"

Post by bobbyjones »

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
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

Re: Class System for "entities"

Post by CaptainMaelstrom »

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
User avatar
I~=Spam
Party member
Posts: 206
Joined: Fri Dec 14, 2012 11:59 pm

Re: Class System for "entities"

Post by I~=Spam »

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
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest