I’m working on my mobile learning app. And I use json module to make things like settings, progress meter, data container etc. So, I write each one as a module I require in scene code
I need each module in each scene, but I don’t want to require them from each one. I need to import my modules in one scene, and then make them usable in each file. I’m beginner, so I don’t know many things. But I have 3 ideas how to do it:
- I require each my module in main.lua, then I use composer.setVariable ( “myModuleVariable” ). In this case I’ll be able to use all this modules from any scene file by composer.getVariable ( “mMV” )
- I also require each my module in main.lua, then I pass this modules in scene params.
- First step like in any previous, but I require modules by setting them to global variables instead of using local. myModule = require “myModuleName” instead of local myModule = require “myModuleName”
I can perform first step not in main.lua, but in some transitional scene. And I think, it’ll he better. But I don’t know which way is better to use, or none of them. Please, help me with it. Thanks
P.S.
The concept of my modules is that module have a few functions it load/save data in files, and have own variable, where it store loaded data. So I need to be able to use this functions from “one instance of module” that is required and created once.