thanks for your help.
I do not have a common game.lua module in wich I replace values in each level, NO.
I have 10 different modules and I’m getting errors in the composer.gotoScene()
I have a progress module:
---------------------progress.lua------------------------- --save and load last level local M = {} local composer = require( "composer" ) local json = require( "json" ) local lastLevel = composer.getVariable( "level" ) local filePath = system.pathForFile( "levels.json", system.DocumentsDirectory ) function M.saveLevel() if filePath then local contents = json.encode(lastLevel) file:write( contents ) io.close( filePath ) return true else return false end function M.loadLevel() local file = io.open( filePath, "r" ) if file then -- read all contents of file into a string local contents = file:read( "\*a" ) lastLevel = json.decode(contents); io.close( file ) return lastLevel end return nil end return M
ok, now in every scene at top I require the progress module and
set the “level” variable to level # in this example 3, but it’s
the same in level 1 and level 2.
---------------------level\_3.lua-------------------------- local progress = require( "progress" ) local physics = require( "physics" ) physics.start() composer.setVariable( "level", 3 )
I call the M.loadLevel() function in every levels#.lua scene “create”
and the M.saveLevel() function in every levels#.lua scene “show”
-- create() function scene:create( event ) progress.loadLevel() end -- show() function scene:show( event ) progress.saveLevel() end
ok, and in menu.lua following @nick said
local function gotolastLevel() composer.gotoScene( progress.lastLevel ) end
but I’, getting this error