How can I make a database for many levels?

I am making an app that will have at least 50 levels before release and I was wondering If I had to make each individual level in a .lua file or if there was some way I could compile them all into one .lua file. Thanks!

You could make 50 different files, but (in my opinion) that’s a silly way to handle it.

My current game has 42 levels – and I have one play.lua scene file and then a levels.lua file with the explicit info for each level. For example, a level looks like this:

--level1 17= { 0, 0, 0, 5, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 6, 0, 0, 4, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 4, 0, 0, 0, 0, 2, 0, 6, 0, 2, 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 4, 0, 0, 3, 0, 5, 7, 0, 0, 0, 6, 0, 0, 0, 0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 0, 0, 3, 0, 6, 0, 0, 4, 0, 0, 2, 5, 0, 2, 0, 0, 0, 0, 5, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, },

The play mechanics are the same for each level (and that holds true for just about every game) so the only thing that needs to change is in that level table.

In my case it’s a puzzle game, but when I was working on a platformer I did the same thing – all core mechanics were in a single file and I just pulled in the specific data needed for each level.

Now, after I said it was silly to have 50 different level files I’d like to backtrack a little – it’s not silly to have 50 different data files. In my puzzle game I have one file with all 42 tables in it. But for my platformer I actually had a data file for each level – simply because each level was a Tiled map and in order to go back and edit them I had to keep them separate. But the code that actually ran all the levels? Just in that one play.lua file.

I hope that helps.

 Jay

well lua is my first language and I have no idea what you just said hahaha thanks though.

If you’re a newbie I’ll modify my answer to something like this…

Do whatever works in order to get your first game done. Worry about “best way to do things” later.

I’m a big believer in “shipping” your game – whether that means it’s in the App Store or just on your device to play, just get it done. :slight_smile:

 Jay

PS - In general, you’re going to have multiple Lua files per project. While you could shoehorn everything into a single file, that’s a bad way to handle things. That’s an exception to my “do whatever works” rule because it will cause you more problems than it’s worth.

I released my first app “super pooper” april 1st its a flappy bird clone lol. I don’t care how long it takes though I am creating a database.

I don’t think ‘whatever works’ is a good idea for 50 levels, tbh :slight_smile:

If you don’t understand JAW’s original suggestion that’s fine. But that means that you are going to have levels where the code is all pretty much the same, except the layouts and numbers of items are different - say like in Super Mario games where the game is all the same more or less but blocks, ladders, pipes and so on move about.

If you are going to do it this way, then I would put all the stuff that changes in a separate function on its own so that most of the code is identical - that way you can create a new level by copying another one and just changing the set up bit.

Can I suggest that you don’t aim for 50 but try (say) about ten, and as JAW says, release something ? Then study the coding side of programming rather than Corona - things like arrays, lists, stacks, tables, functions and so on, this will help you with your second game.

What JAW is suggesting, basically, is that you have a table of information that describes how the level is put together - this goes here, that goes there, and your program looks at this to figure out what to do.  So in something like ‘Candy Crush’ the table says what sweets are where on the screen for example.

So when adding or changing levels you don’t actually change the program, you change the information table.

You could make 50 different files, but (in my opinion) that’s a silly way to handle it.

My current game has 42 levels – and I have one play.lua scene file and then a levels.lua file with the explicit info for each level. For example, a level looks like this:

--level1 17= { 0, 0, 0, 5, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 6, 0, 0, 4, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 4, 0, 0, 0, 0, 2, 0, 6, 0, 2, 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 4, 0, 0, 3, 0, 5, 7, 0, 0, 0, 6, 0, 0, 0, 0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 0, 0, 3, 0, 6, 0, 0, 4, 0, 0, 2, 5, 0, 2, 0, 0, 0, 0, 5, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, },

The play mechanics are the same for each level (and that holds true for just about every game) so the only thing that needs to change is in that level table.

In my case it’s a puzzle game, but when I was working on a platformer I did the same thing – all core mechanics were in a single file and I just pulled in the specific data needed for each level.

Now, after I said it was silly to have 50 different level files I’d like to backtrack a little – it’s not silly to have 50 different data files. In my puzzle game I have one file with all 42 tables in it. But for my platformer I actually had a data file for each level – simply because each level was a Tiled map and in order to go back and edit them I had to keep them separate. But the code that actually ran all the levels? Just in that one play.lua file.

I hope that helps.

 Jay

well lua is my first language and I have no idea what you just said hahaha thanks though.

If you’re a newbie I’ll modify my answer to something like this…

Do whatever works in order to get your first game done. Worry about “best way to do things” later.

I’m a big believer in “shipping” your game – whether that means it’s in the App Store or just on your device to play, just get it done. :slight_smile:

 Jay

PS - In general, you’re going to have multiple Lua files per project. While you could shoehorn everything into a single file, that’s a bad way to handle things. That’s an exception to my “do whatever works” rule because it will cause you more problems than it’s worth.

I released my first app “super pooper” april 1st its a flappy bird clone lol. I don’t care how long it takes though I am creating a database.

I don’t think ‘whatever works’ is a good idea for 50 levels, tbh :slight_smile:

If you don’t understand JAW’s original suggestion that’s fine. But that means that you are going to have levels where the code is all pretty much the same, except the layouts and numbers of items are different - say like in Super Mario games where the game is all the same more or less but blocks, ladders, pipes and so on move about.

If you are going to do it this way, then I would put all the stuff that changes in a separate function on its own so that most of the code is identical - that way you can create a new level by copying another one and just changing the set up bit.

Can I suggest that you don’t aim for 50 but try (say) about ten, and as JAW says, release something ? Then study the coding side of programming rather than Corona - things like arrays, lists, stacks, tables, functions and so on, this will help you with your second game.

What JAW is suggesting, basically, is that you have a table of information that describes how the level is put together - this goes here, that goes there, and your program looks at this to figure out what to do.  So in something like ‘Candy Crush’ the table says what sweets are where on the screen for example.

So when adding or changing levels you don’t actually change the program, you change the information table.