There are several ways to handle this problem. The links I game you before is just one way, and a good way. But you could also do any of these:
-
make ‘playerName’ global in main. It is then accessible in both other.lua and main.lua and any other module of the project
(not recommended - but has been done)
-
make a ‘global module’. A module that holds any variables that you want to be accessed in some or all of your modules. Developers often call these modules ‘common.lua’ ‘global.lua’ etc…
--============================= -- global.lua -- simple module to share variables between modules --============================= local M = {} M.playerName = "any name" M.score = 1000 M.life = 100 return M --============================= -- other.lua --============================= local g = require("global") g.playerName = "Bob" --============================= -- main.lua --============================= local g = require("global") print(" name from global module is " .. g.playerName)
-
use the 'eventDispatch as noted in previous response
-
use composer, see this link :
https://docs.coronalabs.com/api/library/composer/gotoScene.html#going-to-another-scene