Understanding strings help!

So I’ve got a level select menu template and implemented it into my game, everything is going well, I can go to the menu and select a level etc. However no matter which level I click on it goes to the same scene and I am unsure how to change this. Here are my level select templates, the ones provided on the corona website.

I am having trouble understanding this part, could someone explain it better than the corona tutorials which are very brief? Like how do I make levels become unlocked, how to determine the number of stars/score you get in each level etc.

 -- define the array to hold each button -- local buttons = {} -- -- Determine the maxLevels from the myData table. This is where you determine how many -- levels your game supports. Loop over them, generating one button, group for each. -- for i = 1, myData.maxLevels do -- create the button buttons[i] = widget.newButton({ label = tostring( i ), id = tostring( i ), onEvent = handleLevelSelect, emboss = false, --properties for a rounded rectangle button... shape="roundedRect", width = 48, height = 32, font = native.systemFontBold, fontSize = 18, labelColor = { default = { 1, 1, 1}, over = { 0.5, 0.5, 0.5 }}, cornerRadius = 8, labelYOffset = -6, fillColor = { default={ 0, 0.5, 1, 1 }, over={ 0.5, 0.75, 1, 1 } }, strokeColor = { default={ 0, 0, 1, 1 }, over={ 0.333, 0.667, 1, 1 } }, strokeWidth = 2 }) -- position the button in the grid and add to the scrollView buttons[i].x = xOffset buttons[i].y = yOffset levelSelectGroup:insert(buttons[i]) -- -- Check to see if the player has achieved this level or not. The .unlockedLevels -- value tracks the maximum level they have unlocked. This lets them play previous -- levels if they wish to try and do better. -- -- However first, check to make sure this value has been set. For a new user this -- value should be 1 if it's not been set. -- -- If the level is locked, disable the button and fade the button out. -- if myData.settings.unlockedLevels == nil then myData.settings.unlockedLevels = 1 end if i \<= myData.settings.unlockedLevels then buttons[i]:setEnabled( true ) buttons[i].alpha = 1.0 else buttons[i]:setEnabled( false ) buttons[i].alpha = 0.5 end -- -- Now generate stars earned for each level but only if: -- a. the levels table exists -- b. There is a stars value inside of the levels table and -- c. The number of stars is greater than 0 (no need to draw 0 stars, eh?) -- -- Generate the star and position it relative to the button it goes with. local star = {} if myData.settings.levels[i] and myData.settings.levels[i].stars and myData.settings.levels[i].stars \> 0 then for j = 1, myData.settings.levels[i].stars do star[j] = display.newPolygon( 0, 0, starVertices ) star[j]:setFillColor( 1, 0.9, 0) star[j].strokeWidth = 1 star[j]:setStrokeColor( 1, 0.8, 0 ) star[j].x = buttons[i].x + (j \* 16) - 32 star[j].y = buttons[i].y + 8 levelSelectGroup:insert(star[j]) end end -- -- Compute the position of the next button. This is set to draw 5 wide. It also spaces based on -- the button width and height + initial offset from the left. -- xOffset = xOffset + 75 cellCount = cellCount + 1 if cellCount \> 5 then cellCount = 1 xOffset = 64 yOffset = yOffset + 45 end end --

The problem is very likely not in the code you posted above. Instead it’s likely in “playGUI.lua”. Consider this:

local function handleLevelSelect( event ) if ( "ended" == event.phase ) then -- -- event.target is the button. The ID is a number indicating the level going to. -- the "game" scene will use this setting to determine which level to play. This could -- be done by passing parameters too. -- -- Also purge the game scene so we get a fresh start. -- myData.settings.currentLevel = event.target.id composer.removeScene( "playGUI", false ) composer.gotoScene( "playGUI", { effect = "crossFade", time = 333 } ) end end

You capture event.target.id which should be a string that equals the level you selected. Then you goto playGUI. You’re not passing the ID via parameters so I’m assuming that playGUI you are looking at the value of myData.settings.currentLevel to decide how to configure the game to play that level.

Rob

The problem is very likely not in the code you posted above. Instead it’s likely in “playGUI.lua”. Consider this:

local function handleLevelSelect( event ) if ( "ended" == event.phase ) then -- -- event.target is the button. The ID is a number indicating the level going to. -- the "game" scene will use this setting to determine which level to play. This could -- be done by passing parameters too. -- -- Also purge the game scene so we get a fresh start. -- myData.settings.currentLevel = event.target.id composer.removeScene( "playGUI", false ) composer.gotoScene( "playGUI", { effect = "crossFade", time = 333 } ) end end

You capture event.target.id which should be a string that equals the level you selected. Then you goto playGUI. You’re not passing the ID via parameters so I’m assuming that playGUI you are looking at the value of myData.settings.currentLevel to decide how to configure the game to play that level.

Rob