I’m not sure if this is in the right forum, apologies if it isn’t.
I’m using the director class to move between my scenes. The app is a game, following a standard format of menus, with level lists.
I have a variable, which is set inside main.lua, called currentLevel. It’s set to 1 by default. When the user clicks a level from the level select screen I change this variable to the number of the level selected.
This variable isn’t being passed through to my game.lua file though. Inside game.lua the currentLevel variable is set to ‘1’ - which I find very strange.
Any ideas? Code below:
main.lua:
currentLevel = 1
print("The current level from main: " .. currentLevel)
gamemenu.lua:
[code] local objectTouch = function( event )
if event.phase == “release” then
audio.play( tapSound )
audio.stop( gameMusic )
– Go to level
currentLevel = params.level
print("The current level from menu: " … currentLevel)
director:changeScene( “loadthegame” )
end
end[/code]
loadthegame.lua (in full)
[code]module(…, package.seeall)
– Main function - MUST return a display.newGroup()
function new()
print("The current level from loader: " … currentLevel)
local localGroup = display.newGroup()
local theTimer
local loadingImage
local showLoadingScreen = function()
loadingImage = display.newImageRect( “loading.png”, 480, 320 )
loadingImage.x = 240; loadingImage.y = 160
localGroup:insert( loadingImage )
local goToLevel = function()
director:changeScene( “thegame” )
end
theTimer = timer.performWithDelay( 1000, goToLevel, 1 )
end
showLoadingScreen()
unloadMe = function()
if theTimer then timer.cancel( theTimer ); end
end
– MUST return a display.newGroup()
return localGroup
end[/code]
The outputs the following in the terminal:
The current level from main: 1
The current level from menu: 6
The current level from loader: 1 [import]uid: 62042 topic_id: 15570 reply_id: 315570[/import]
[import]uid: 62042 topic_id: 15570 reply_id: 57493[/import]