My game has more than 200 .lua files. is that ok ?

Hi, 

I’m working on a game consisted of +200 levels. I’m just afraid that this huge amount of .lua files will affect the performance. Am I right to worry or everything is going to be fine?

By the way. I’m purging all the scenes using this line in main.lua :

[lua]local storyboard = require “storyboard”
storyboard.purgeOnSceneChange = true;
[/lua]

thanks.

Depends what you mean by .lua files. If each lua file represents a scene, each containing game logic, control handlers etc. then it’s a pretty inefficient way of doing things. Maybe not in terms of performance but in terms of editing and maintaining the code.

To optimize your game you have to don’t load all 200 files. Load only what you actualy need. For example:

if level==1 then    require("level1") else      ... end or require("level"..level)

I check the code 10 times before moving to another scene. guess that wont be a problem.

Hi, remiduchalard.

Yes, that’s what I’m doing. I just wanted to make sure that 200+ lua files in the project file won’t affect the performance.

thanks.

What I mean is have you got lots of code repeated in all the different .lua files?

Say you have code that makes a character jump, would that be in 200 files or just one?

Hi, Repeated in all 200 files.

Ok. This isn’t a good way of doing things. What if you wanted to change how the character jumps? That’s 200 changes instead of one.

You should ideally have one .lua file which handles gameplay (which maybe links to a few others containing key functions), and then level data in either individual files or one big table. You store the level you are currently playing to disk or as a global variable and only import the data you need for that level.

that’s actually a good insight. But, it won’t help with a game like mine because each level has different logic.

You can move your functions that are common among all modules to a module that you load in each scene. That will help a lot. Then each scene can be responsible for the code that’s unique to it.

There is a programming principle called DRY - Don’t Repeat Yourself

It can save a lot of time and headache on big projects.

Rob

Depends what you mean by .lua files. If each lua file represents a scene, each containing game logic, control handlers etc. then it’s a pretty inefficient way of doing things. Maybe not in terms of performance but in terms of editing and maintaining the code.

To optimize your game you have to don’t load all 200 files. Load only what you actualy need. For example:

if level==1 then    require("level1") else      ... end or require("level"..level)

I check the code 10 times before moving to another scene. guess that wont be a problem.

Hi, remiduchalard.

Yes, that’s what I’m doing. I just wanted to make sure that 200+ lua files in the project file won’t affect the performance.

thanks.

What I mean is have you got lots of code repeated in all the different .lua files?

Say you have code that makes a character jump, would that be in 200 files or just one?

Hi, Repeated in all 200 files.

Ok. This isn’t a good way of doing things. What if you wanted to change how the character jumps? That’s 200 changes instead of one.

You should ideally have one .lua file which handles gameplay (which maybe links to a few others containing key functions), and then level data in either individual files or one big table. You store the level you are currently playing to disk or as a global variable and only import the data you need for that level.

that’s actually a good insight. But, it won’t help with a game like mine because each level has different logic.

You can move your functions that are common among all modules to a module that you load in each scene. That will help a lot. Then each scene can be responsible for the code that’s unique to it.

There is a programming principle called DRY - Don’t Repeat Yourself

It can save a lot of time and headache on big projects.

Rob