Page 1 of 1

best way to require and make instances

Posted: Wed Aug 07, 2024 9:42 am
by Lovingsoul1337
i have here 3 examples how i did that.
now im not sure what is the best way to make this what are the conventions ?

https://pastebin.com/LZdcV1V6

-in the main.lua

using the new keyword directly after the require feels like the best(but could not work if i do instances in instances or ?)

-in the scenemanager

i make this in load and feels somewhat clunky

-in the playscene

i make it in the constructor and feels somewhat okay or good

how you do that ?

best regards

Lovingsoul1337

Re: best way to require and make instances

Posted: Wed Aug 07, 2024 4:06 pm
by dusoft
Functional programming = arrays
Object oriented - you have plenty of libraries that implement that, e.g. Hump class: https://hump.readthedocs.io/en/latest/class.html

Re: best way to require and make instances

Posted: Fri Aug 09, 2024 8:24 am
by Lovingsoul1337
i dont want a lib, i want know what is the best way or the convention to make instances. and showed 3 ways how i did that in my code and im not sure what is the best.

and ps. i want to do that on my own not using any lib at all for this. ^^

best regards

Lovingsoul1337

Re: best way to require and make instances

Posted: Fri Aug 09, 2024 1:39 pm
by dusoft
There is no right way. There are many ways and it's up to you to decide. You don't have to use any lib, but you can study their code and either copy that style or disregard it. Up to you.