Reset Level

When my game completes it brings up a try again or congratulations you completed the level. How do i reset the level after a try again?

I want to move all pieces back to their original location on the board.

[import]uid: 72372 topic_id: 12783 reply_id: 312783[/import]

Depends on how your game is set up… gonna have to post some code. [import]uid: 28912 topic_id: 12783 reply_id: 46855[/import]

I’m not sure what code you are looking for. The code below is what I show at the completion of the game. It brings up a positive or a negative response. When I click the alert it disappears but the board is in the same position it completed in.

[lua]if (findBlock(1,1) == findBlock(1,2)) then
native.showAlert(“Uh-oh”,“You can’t do that.”,{“Try Again”});

–this stops our alert box from showing
return false
end
–DO STUFF
native.showAlert(“level complete”,“success”,{“Awesome!”});
return true
end[/lua] [import]uid: 72372 topic_id: 12783 reply_id: 46861[/import]

I recommend using director class, and just reloading the lvl.lua [import]uid: 28912 topic_id: 12783 reply_id: 46864[/import]

How do I do that? I am using the director.lua file

Do I just place a reset button, tie to the page and reload the screen like I am transitioning to the page again? [import]uid: 72372 topic_id: 12783 reply_id: 46866[/import]

You just need two files… you need your level file… and then you need a load level file. When your game is over… and you click retry… the retry button would switch scenes to your load level file…

director:changeScene( loadLevel, "crossfade" )  

and your load level file would look something like this.

module(..., package.seeall)  
  
-- Main function - MUST return a display.newGroup()  
 function new()  
 local localGroup = display.newGroup()  
 local theTimer  
 local loadingImage  
  
 local showLoadingScreen = function()  
  
  
 local goToLevel = function()  
 director:changeScene( "lvl" )  
 end  
  
 theTimer = timer.performWithDelay( 10, goToLevel, 1 )  
 end  
  
 showLoadingScreen()  
  
 unloadMe = function()  
 if theTimer then timer.cancel( theTimer ); end  
  
 if loadingImage then  
 loadingImage:removeSelf()  
 loadingImage = nil  
 end  
 end  
  
 -- MUST return a display.newGroup()  
 return localGroup  
end  
  

[import]uid: 28912 topic_id: 12783 reply_id: 46868[/import]

Okay I have the level file and the load level file is just similar to the file I have to transition from my splash screen to my titlescreen so I get that.

In regards to the director line. Where do I put that line? Do I put that with the coding above that I posted after the alert as an if then statement?

[import]uid: 72372 topic_id: 12783 reply_id: 46872[/import]

Ive never worked with native.showAlert before… but this link shows what you would need to do…

http://developer.anscamobile.com/reference/index/nativeshowalert

It looks to me though, that whatever index your “retry” button is, is where you would put the director line.
For instance if your retry button is indexed as 1… then…

local function onComplete( event )  
 if "clicked" == event.action then  
 local i = event.index  
 if 1 == i then  
 director:changeScene( loadLevel)   
 end  
 end  
end  

and of course you would need to link the onComplete function to your “retry” btn [import]uid: 28912 topic_id: 12783 reply_id: 46874[/import]

who can i reset my modeule? or even remove the LEVEL 1 = REQUIRE?
thanks
[lua]module(…, package.seeall)

function new()

local localGroup = display.newGroup()
local level1 = require (“nivel1”)
–localGroup:insert(level1)
local backbutton = display.newImage (“images/interfas/backbutton.png”)
backbutton.x = 160
backbutton.y = 350
localGroup:insert(backbutton)
–> This places our “back” button

local function pressBack (event)
if event.phase == “ended” then
director:changeScene (“menu”)
Runtime:removeEventListener(“enterFrame”,gameListener)
end
end

backbutton:addEventListener (“touch”, pressBack)
–> This adds the function and listener to the “back” button



return localGroup
end[/lua] [import]uid: 110762 topic_id: 12783 reply_id: 84248[/import]