What to keep separate from main.lua

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

What to keep separate from main.lua

Post by Bindie » Thu Apr 02, 2015 7:35 pm

Hey! The game I'm making is currently kinda big. Next time I'm to make a game, I feel excited to use separate .lua files for example NPC's, Player, Items and so on.

If I were to do it today it would be kinda experimental, would like some advice on the matter. What to separate into .lua sections, requiring them in main.lua? Of course to make thing easier to find.

Happy easter.

User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: What to keep separate from main.lua

Post by arampl » Thu Apr 02, 2015 11:56 pm

An excellent question. I'm also would like to know.

User avatar
Jeeper
Party member
Posts: 544
Joined: Tue Mar 12, 2013 7:11 pm

Re: What to keep separate from main.lua

Post by Jeeper » Fri Apr 03, 2015 12:45 am

Personal preference, but what I do is to have as many separate file as possible and do basically nothing aside from calling parent functions in main.lua. I find it a lot easier to keep a large project manageable to keep everything separated. A single file with thousands of lines of code is a lot harder to navigate than several files with only a few hundred lines.

bobbyjones
Party member
Posts: 720
Joined: Sat Apr 26, 2014 7:46 pm

Re: What to keep separate from main.lua

Post by bobbyjones » Fri Apr 03, 2015 3:59 am

Generally people separate files by purpose. A file should do one thing and do one thing only. Example if i have i have a gamestates.lua file and it handles all of my gamestates then well it can and will get very big as i will have a lot of gamestates. So i would separate my files into smaller more specific files. In this case i would make a gamestates folder and throw all of my gamestates in there as separate files. menu.lua, level1.lua, pause.lua. credits.lua and so forth. so now each of those do one thing and one thing only.
Do you frequently have great ideas but immediately lose them? Check out the MVP for my website called IdeaVault. It is designed to solve that problem. Desktop browsers only currently.

User avatar
SuperZazu
Citizen
Posts: 56
Joined: Sun Jun 10, 2012 2:06 pm
Location: France
Contact:

Re: What to keep separate from main.lua

Post by SuperZazu » Fri Apr 03, 2015 7:48 am

bobbyjones wrote:Generally people separate files by purpose. A file should do one thing and do one thing only. Example if i have i have a gamestates.lua file and it handles all of my gamestates then well it can and will get very big as i will have a lot of gamestates. So i would separate my files into smaller more specific files. In this case i would make a gamestates folder and throw all of my gamestates in there as separate files. menu.lua, level1.lua, pause.lua. credits.lua and so forth. so now each of those do one thing and one thing only.
I agree with this :)
At the end, the idea is that your main.lua is just a bunch of functions that updates/draw the current "game state" (where all your code really is). That allows you to split your game into files (like bobbyjones said "menu.lua", "gameover.lua", and so on), and it is much easier to maintain your code.
If you don't really understand what I'm trying to say, here's an example of what I have in mind (look in the folder "example"). I can also recommend this link and this link, these will be a great help for you if you start wondering about game architecture.

Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

Re: What to keep separate from main.lua

Post by Bindie » Fri Apr 03, 2015 3:29 pm

Game architecture, nice!

User avatar
kikito
Inner party member
Posts: 3152
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: What to keep separate from main.lua

Post by kikito » Fri Apr 03, 2015 8:47 pm

I also tend to leave very little stuff on main. Here's my latest example:

https://github.com/kikito/ekrixion/blob/master/main.lua

Notice that in other projects I might need more functions (for mousepressed etc).
When I write def I mean function.

User avatar
bartbes
Sex machine
Posts: 4944
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: What to keep separate from main.lua

Post by bartbes » Fri Apr 03, 2015 9:35 pm

I tend to do the same, make the main.lua simply "bootstrap" the game by selecting a state and handing things over to the state manager.
Then in turn, I usually have a file per class, and a file per state.

Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

Re: What to keep separate from main.lua

Post by Bindie » Sun Apr 05, 2015 5:52 pm

I think I'm Swedish, "bootstrap"?

User avatar
Rukiri
Citizen
Posts: 68
Joined: Mon Jun 27, 2011 5:52 am

Re: What to keep separate from main.lua

Post by Rukiri » Thu Apr 16, 2015 1:27 am

Main should just be your startup, you should also have files for every map and cut scene, you also want to keep functionality scripts separate just code once and import when needed.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests