loading level file

Hi
I’am using yours class and it’s great. Thanks.
I have fast question…
I have game with 30 levels… after level is complete I call a loadinglevel1… loadinglevel2 … file.

module(..., package.seeall)  
  
function new()  
 local localGroup = display.newGroup()  
 local theTimer  
 local textObj  
 local showLoadingScreen = function()  
 textObj = display.newImage("loading.png")  
  
  
 local nextScreen = function()  
 director:changeScene("level2")  
 end  
 theTimer= timer.performWithDelay(1000, nextScreen, 1)   
 end  
 showLoadingScreen()  
  
 unloadMe = function()  
 if theTimer then timer.cancel( theTimer ); end  
  
 if textObj then  
 textObj:removeSelf()  
 textObj = nil  
 end  
 end  
 return localGroup  
end  

Everything works great, but the question is… If I have a 30 levels I have to make 30 files loadinglevel… ? Or maybe is a better solution …?
Thank you. [import]uid: 13156 topic_id: 5822 reply_id: 305822[/import]

You can use only one file and handle the levels by a global variable. [import]uid: 8556 topic_id: 5822 reply_id: 19952[/import]

You mean make one loadinglevel file and level1 = “level1” … right ? [import]uid: 13156 topic_id: 5822 reply_id: 19983[/import]

You can create a settings.lua file that keeps all the global variables and when you go to the loadingLevel just test the value.
settings.lua

module(..., package.seeall)  
  
local tabVars = {}  
--  
tabVars["level"] = 1  
  
function settings:getVar ( pVarName )  
 return tabVars[pVarName]  
end  
  
function settings:setVar ( pVarName, pVarValue )  
 tabVars[pVarName] = pVarValue  
end  

loadinglevel.lua

...  
if settings:getVar ( "level" ) == 1 then  
 ...  
end  
...  

levelN.lua

... settings:setVar ( "level", settings:getVar ( "level" ) + 1 ) director:changeScene("loadinglevel","fade") ... [import]uid: 8556 topic_id: 5822 reply_id: 20121[/import]

Hi Ricardo…
I have to say that is working great. One loading file it’s a good solution but when I am in level 3 I can’t go back to level 1 because var (“level”) == 3 . hmmm
I think that I’am very close right now to make unlocking level’s system.:slight_smile:
Thank you

Solved:
I just add :
settings:setVar (“level”,1 ) to button level 1 …
settings:setVar (“level”,2 ) to button level 2…
.
.
.
.
cool :slight_smile:
Unlock level’s system and I am done :slight_smile: [import]uid: 13156 topic_id: 5822 reply_id: 24918[/import]