Efficiency in a Codea file

I have been making a game for iOS in Codea. It is a patterning game for younger children to learn to pattern, but it’s taking a long time. I will have 25 levels in the game. I wanted to know how to go about making all of those levels efficiently with variables all in one file. Can anybody give me suggestions on how to make this properly.

@melkxy - if your levels are stored in file(s), you will need to store all them as text, because Codea doesn’t have the option to store objects.

However, depending on complexity, it may be easier simply to include them in a separate tab along with your code, as tables, eg

    {a=3,b=4,c={5,6,7},d="aaa"},  --level 1
    { etc}, --level 2

Level[1] --is a table with all the level 1 details

If you prefer to store the levels separately in one or more files, it is a question of the best way to encode your level details. There are many ways to do it.

You could store a set of lines for each level, where each line is a variable value, and then read them in.

You could store Codea code for each level and use loadstring to execute that code when the file is read in. This may be easiest for creating things like tables.

So it depends on exactly what you are storing for your levels.

If you need a level map that shows the location of objects, a good way to do it, assuming your map is divided into tiles, is to create a tilemap with coded characters that tell Codea what to put in each square, eg

wwwww  wwwwwww
w a    w     w
w      w     w
w  b         w

In my levels I have a incomplete pattern and a few shapes that are dragable and one of those fits in the blank space. I’ve done everything for one level, and it works, but it’s not efficient because it’s like 80 lines of code. I’m putting my objects and what not in tables but I can’t seem to figure out how to display them efficiently.

Share some code and maybe we can help

I started learning Lua from a YouTube channel about 2 months ago. So I’m not the greatest at coding yet.

if(levelChosen == 1)then
sprite(“Dropbox:iceberg”, WIDTH/2, HEIGHT/2, 1024, 768)
sprite(worldOneLevelOne[1], WIDTH/2-250, 100, 250, 150)
sprite(worldOneLevelOne[2], WIDTH/2-150, 100, 160, 130)
sprite(worldOneLevelOne[3], WIDTH/2-50, 100, 250, 150)
sprite(worldOneLevelOne[2], WIDTH/2+150, 100, 160, 130)
sprite(worldOneLevelOne[3], WIDTH/2+250, 100, 250, 150)

This is level 1, I’ve got tables of sprites that I am displaying. Also I’ve got separate variables to draw and the variable I called shapeOne I have made it dragable.

Ok, now what you need to figure out is how much of this structure is the same from one level to the next, i.e. will the names of things be the same, will there be the same number of pictures, etc.

Anything that is consistent from level to level can be put into tables easily. Anything that varies between levels will need some special code.

So for now, I would leave it the way it is. Do level two the same way, and level three. If you see a pattern emerging, you can make the code more compact.

But right now, you have hardly any code to worry about. It is really very small. Some of my levels are five times longer. So don’t worry about size just yet.

Ok thanks I will try to do that thanks