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.
What to keep separate from main.lua
Re: What to keep separate from main.lua
An excellent question. I'm also would like to know.
Re: What to keep separate from main.lua
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.
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: What to keep separate from main.lua
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.
Re: What to keep separate from main.lua
I agree with thisbobbyjones 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.
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.
Re: What to keep separate from main.lua
Game architecture, nice!
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: What to keep separate from main.lua
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).
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.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: What to keep separate from main.lua
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.
Then in turn, I usually have a file per class, and a file per state.
Re: What to keep separate from main.lua
I think I'm Swedish, "bootstrap"?
Re: What to keep separate from main.lua
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.
Who is online
Users browsing this forum: Semrush [Bot] and 3 guests