This question has boggled me for a sometime now. As an amateur programmer, I have worked on projects that require no more than 3 files at most. But, ever since I started working on my mobile game, I realized that I need multiple files to handle the development. I see the benefit in having multiple files, but there are times when I’m confused about the following:
- When does it make sense to create a module instead of functions within a file?
For instance, there are functions I have created for a level selection scene. The functions include making a grid, sliding, saving and loading. I am not sure whether I should place them in an external module that manages level selection.
- How do you determine where a function belongs?
Should the function for creating a grid with level buttons be placed in a level selection scene or an external module?
- How should files interact with one another?
Suppose that there are three files in question, game_scene.lua, level_selection_scene.lua, and level_manager_module.lua. The purpose of the level_selection is to instantiate methods, such as saving and loading, locking and unlocking, and displaying points. The methods are all placed in the level manager module which are imported in the level_selection page. After a game level ends and a score needs to be saved, should the information regarding score be dispatched directly to the level manager module or via the level_selection_scene file?
- What are some common Do’s and Not Do’s when handling multiple files?
Thank you in advance.

