Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Better way to pass parameters between scenes
Started by mashtaliaryaroslav Jan 31 2020 06:21 AM

3 replies to this topic
composer variable module
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

mashtaliaryaroslav

[GLOBAL: userInfoPane.html]
mashtaliaryaroslav
  • Observer

  • 1 posts
  • Corona SDK

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:

  1. 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" )
  2. I also require each my module in main.lua, then I pass this modules in scene params.
  3. 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.



[TOPIC: post.html]
#2

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,205 posts
  • Corona SDK

A global settings module is a god way of sharing data between scenes if you have a lot of it.  If it is 1 or 2 then just pass them as parameters.



[TOPIC: post.html]
#3

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 780 posts
  • Corona SDK

My approach has been to use a "master module" that requires all the other modules.  Thus, every module can be accessed through the master module with creating circular references.

 

Check out this forum post



[TOPIC: post.html]
#4

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 780 posts
  • Corona SDK

Oh, the post above also references another post that might be helpful




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: composer, variable, module