Page 2 of 2
Re: Lua access parent scope var with same name as in local scope ?
Posted: Mon Dec 18, 2017 8:42 pm
by RagingDave
I don't want to discourage your idea of doing OO with inheritance and so forth but maybe read a little about composition over inheritance and prototype based programming.
Lua is in my opinion a natural fit for these paradigms. I would also advise against using an OO library and instead starting just with plain tables as objects and just adding the OO mechanisms you really need.
Re: Lua access parent scope var with same name as in local scope ?
Posted: Tue Dec 19, 2017 6:08 pm
by Davïd
The plan was to groupe gameobject by type, for example :
- gameobject
-- character
--- player
--- monster
player will inherit fields and methods from character and so on for gameobject.
- gameobject will contain basic stuff like x y position in world maybe an ID
- character will contain a component with hp, an other one for a collider
- player will have a sprite and business logic
But maybe I shouldn't bother with 'inheritance' (it's rather some way to organize stuff) and create every object from scratch.
There are indeed interestings concepts behing protype programming :
http://gameprogrammingpatterns.com/prototype.html
https://en.wikipedia.org/wiki/Prototype ... rogramming
But does it work to create object on the fly ? Can you really have organized code like that ?
The part on "Prototypes for Data Modeling" from gameprogrammingpatterns.com look nice for data but I don't know for building real world object.