Advice on Storing Level Data and DIY Editor?

I’m working on a little grid-based puzzle game and currently load the initial grid state by reading a table from a separate .lua file.

e.g.   level1.lua  containing something like,

gridTable={ {1, 2, 3, 4}, {4, 3, 2, 1} }

The above would be used to populate a 4x2 grid of objects with object ‘types’ between 1 and 4.

I would use a different file for each level in the game.

Firstly, is this generally a good way to handle level data and/or is there a better, ‘preferred’, way to do the same thing?

Assuming this is not a terrible plan to start with, what if I wanted to add further attributes to each item in the grid?

Would you recommend a straight forward extension as below:

gridTableA={ {{1, "a"}, {2, "b"}, {3, "c"}, {4, "d"}}, {{4, "d"}, {3, "c"}, {2, "b"}, {1, "a"}} }

or a more explicit:

gridTableB={ {{type=1, char="a"}, {type=2, char="b"}, {type=3, char="c"}, {type=4, char="d"}}, {{type=4, char="d"}, {type=3, char="c"}, {type=2, char="b"}, {type=1, char="a"}} }

Or, does that just come down to personal preference and readbility/manageability?

I am also planning to write a level editor to allow me to quickly set these up in a GUI.

I already know how to create the level editor on screen and manage the table data within the scene, but I’m not sure how I would output it to create the levelN.lua file.

I am loving using Corona and would be very grateful for any advice.

Thanks,

Jules.

I think your approach is just fine. A couple of considerations:

  • Depending on the number of levels (tens, hundreds, thousands), consider whether it makes sense to have one file for each level, or group several levels into one file.

  • If you’re going to generate your levels with a tool, then go for compactness. If you’re going to edit them by hand, then go for readability

  • I prefer gridTableB over gridTableA because it’s simpler to add new attributes using key-value pairs than using arrays (you don’t have to consider the order). Especially handy if you end up with e.g. some tiles that have 3 attributes and others that have 7.

Creating a file when you have all the visual stuff set up should be pretty straightforward, simply iterate through your data, build up a string, and write it to a file.

Thank you, _memo, for your response.

Particularly regarding the key-value pairs, I hadn’t fully considered that flexibility.

I will investigate writing strings to files as it sounds like it will suit my needs perfectly.

Cheers, 

Jules.

@Strange Flight,

Back in 2013 I challenged myself  to make 7 games in 7 days (only finished 6).  Each game came with a rudimentary editor.

While the code is OLD (graphics 1.0), you might still find something useful in running it or trying the released combo game.

https://www.youtube.com/watch?v=oYkZ0MvoUHs

Get the game here(free): https://play.google.com/store/apps/details?id=com.roaminggamer.sgd&hl=en

Get the code here (free): https://gumroad.com/l/tbZN

You will have to set compatibility mode to have any hope of making it run in the current simulator.

Be warned.  The code isn’t pretty.  I only spent about 60 hours on it.

Thanks, Ed,

I will definitley take a look at that code.

Cheers,

Jules.

Update:

Ed, 

Unless I’m doing something wrong, the Gumroad link won’t allow a download without credit card details and a donation.

Sorry about that.  You can put in fake details and 0000 for the credit card and it should work, OR… grab it off my git:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/7g7d_v2.zip

I think your approach is just fine. A couple of considerations:

  • Depending on the number of levels (tens, hundreds, thousands), consider whether it makes sense to have one file for each level, or group several levels into one file.

  • If you’re going to generate your levels with a tool, then go for compactness. If you’re going to edit them by hand, then go for readability

  • I prefer gridTableB over gridTableA because it’s simpler to add new attributes using key-value pairs than using arrays (you don’t have to consider the order). Especially handy if you end up with e.g. some tiles that have 3 attributes and others that have 7.

Creating a file when you have all the visual stuff set up should be pretty straightforward, simply iterate through your data, build up a string, and write it to a file.

Thank you, _memo, for your response.

Particularly regarding the key-value pairs, I hadn’t fully considered that flexibility.

I will investigate writing strings to files as it sounds like it will suit my needs perfectly.

Cheers, 

Jules.

@Strange Flight,

Back in 2013 I challenged myself  to make 7 games in 7 days (only finished 6).  Each game came with a rudimentary editor.

While the code is OLD (graphics 1.0), you might still find something useful in running it or trying the released combo game.

https://www.youtube.com/watch?v=oYkZ0MvoUHs

Get the game here(free): https://play.google.com/store/apps/details?id=com.roaminggamer.sgd&hl=en

Get the code here (free): https://gumroad.com/l/tbZN

You will have to set compatibility mode to have any hope of making it run in the current simulator.

Be warned.  The code isn’t pretty.  I only spent about 60 hours on it.

Thanks, Ed,

I will definitley take a look at that code.

Cheers,

Jules.

Update:

Ed, 

Unless I’m doing something wrong, the Gumroad link won’t allow a download without credit card details and a donation.

Sorry about that.  You can put in fake details and 0000 for the credit card and it should work, OR… grab it off my git:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/7g7d_v2.zip