best way to require and make instances

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
Lovingsoul1337
Citizen
Posts: 61
Joined: Fri Feb 21, 2020 1:26 pm

best way to require and make instances

Post 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
User avatar
dusoft
Party member
Posts: 654
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: best way to require and make instances

Post 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
Lovingsoul1337
Citizen
Posts: 61
Joined: Fri Feb 21, 2020 1:26 pm

Re: best way to require and make instances

Post 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
User avatar
dusoft
Party member
Posts: 654
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: best way to require and make instances

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests