Multiple Entity Bases

I’m trying to create an entity that uses a baseclass, but the baseclass also uses another baseclass. So I’ve got base_powered, base_powerup, and powerup_entity. Base_powered is what all entities that use my power system inherit, base_powerup is what all powerups will inherit from, and powerup_entity is just the entity itself.

Powerup_entity has its ENT.Base set to “base_powerup” and then base_powerup has its ENT.Base set to “base_powered”. The issue I’m having is in powerup_entity, I can call self.BaseClass.SetupDataTables just fine and it calls base_powerup’s SetupDataTables function. But when I call self.BaseClass.SetupDataTables in base_powerup, which I would think should call base_powered’s SetupDataTables function, it is actually calling it’s own SetupDataTable and entering an infinite loop. My question is, what is the appropriate way of having ‘true inheritance’ for multiple bases?

Also do I need to call DEFINE_BASECLASS or is it done automatically for me so long as I have ENT.Base set?

Wouldn’t the ENT.Base of the entity override the ENT.Base of the base?

Don’t use self.BaseClass ever.

As it should if inheritance is working correctly. If I’m not completely overlooking something I think the ‘highest’ parent (base_powered) should be applied first. Which will give me the dtvars set in its SetupDataTables like GetPowered ect. Then the second base should be applied (base_powerup) which will give powerup_entity it’s dtvars from SetupDataTables like GetTimeLeft ect. Then the entity itself will override any of the bases if need be but I want to still be able to call the base class methods.

I think I might just be expecting too much out of the gLua inheritance system though.

Ah so I should be using DEFINE_BASECLASS. I’ll give that a shot real quick.

self.BaseClass always references the direct parent of the object’s class. This is why the BaseClass library exists (which DEFINE_BASECLASS uses).

Thanks Willox, using DEFINE_BASECLASS and the BaseClass upvalue is working perfect.