Proper Entity Inheritance Structure (Help Request)

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
kargon
Prole
Posts: 13
Joined: Tue Sep 09, 2014 2:45 am

Proper Entity Inheritance Structure (Help Request)

Post by kargon »

Hello friends!

First post, but I've been reading/searching quite a bit in the past few weeks and learning a ton. I have both "Beginning Lua Programming" and "Programming in Lua (3rd Edition)". They have helped tremendously, but I've found I learn and retain even more by figuring out a goal and then trying to make it happen.

Anyway, most recently I've gone through goature's awesome tutorials on youtube with great success, but when I tried to apply (and change) some of it to my own project, I've come across a bit of an issue that perhaps you all could help me with.

Basically, I started with the entity structure in goature's tutorials and I've tried to expand it a bit. Instead of just having a "base", I created a base_entity and base_character. The reason for this is because I want all of my char_(name) files to inherit a few more things that are unnecessary in base_entity (like keypressed movements and such).

In my files, you can see that char_sol.lua has keyboard options in function ent:update(dt), however, I want those to be in base_character. I tried creating a function player:update(dt) but nothing was being passed through it, and when adding it to main.lua (under function love.update(dt)) I received an error.

I'm clearly missing something as I still have quite a bit to learn about inheritance and functions. It would be greatly appreciated if someone could point me in the right direction in regards to getting my basic character movement stuff into base_character and out of char_(name). This would also go a long way in regards to moving almost everything into character_base and simply using the char_(name) file for settings (health, speed, images used for animations, etc).

Perhaps I need to rename a few things as well to make sure things are more clear? Perhaps an entire set of player functions? Or can I keep sharing the ent functions from goature's structure?

Thanks so much for any help.

Here are my files:
DL.love
(19.19 KiB) Downloaded 132 times
Note: Currently using sprites off the internet (from Guilty Gear XX) to get my proof of concept working. Hopefully that's OK.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Proper Entity Inheritance Structure (Help Request)

Post by rmcode »

Hey there ... unfortunately I can't help you with your code (don't have the time to read and try to understand it at the moment), so feel free to ignore the following advice.

Basically I prefer to use the closure based approach in my own projects. Here is a tutorial with a few examples:

http://theindiestone.com/forums/index.p ... tables/#II

You could also take a look at kikito's middleclass which is widely used in the community.
Last edited by rmcode on Wed Sep 10, 2014 10:11 pm, edited 1 time in total.
kargon
Prole
Posts: 13
Joined: Tue Sep 09, 2014 2:45 am

Re: Proper Entity Inheritance Structure (Help Request)

Post by kargon »

I'll check that out right now. Thanks!
kargon
Prole
Posts: 13
Joined: Tue Sep 09, 2014 2:45 am

Re: Proper Entity Inheritance Structure (Help Request)

Post by kargon »

Looks like my extra local = {} was causing some issues. Got my controls working in the base_character now. Maybe have other issues, will post back! =)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest