Page 1 of 1

Trying to load classes from files with inheritance

Posted: Mon Sep 23, 2024 2:36 pm
by mikesglove
Apologies if I'm not doing this right, I registered my account mere minutes prior to writing this post.

I use 30log for classes in my game, which represent objects in the world.
In my case, all objects are loaded from their own files in a folder called "entities" and each file is provided a table called "ENT".
Additionally, they (should) automatically inherit methods from their desired entities, of whose name is defined in "ENT.__base"

Right now, what I'm trying to do is create a class for each file prior to actually loading each file and passing that class as "ENT", but it doesn't seem to work :(

What approach should I use for this problem?

Re: Trying to load classes from files with inheritance

Posted: Tue Sep 24, 2024 8:08 pm
by dusoft
Not sure without seeing the code. But indeed you can load (require) mutiple files and create and merge objects from them.

Re: Trying to load classes from files with inheritance

Posted: Wed Sep 25, 2024 2:43 pm
by mikesglove
That was a good enough reply to get me to change the way I load entities.
The approach I use now is simply requiring a function/an object that can be called, to be returned, that itself returns a table.
With the class system, I require the base and extend it.
Thank you 👍

Re: Trying to load classes from files with inheritance

Posted: Wed Sep 25, 2024 9:42 pm
by dusoft
Well, good, showing the way is often better than fixing issues for you :-)

Re: Trying to load classes from files with inheritance

Posted: Thu Sep 26, 2024 12:02 pm
by mikesglove
After all, I was asking for an approach on solving this.

Re: Trying to load classes from files with inheritance

Posted: Thu Sep 26, 2024 3:05 pm
by dusoft
Glad you solved it.