Retry Button in Director Class? How do you do it?

I keep getting errors when I try to reload the same scene that I’m on. For instance, if I was playing my game on Level1, I would make an event listener that would changeScene to Level1. It doesn’t do anything, just sits there. Anyone know how to make a retry button. I desperately need to know. Thanks :slight_smile:

Here is some example code so you can see what im trying to do.

[lua]local retry = ui.newButton{
default = “retry.png”,
over = “retryin.png”,
}
retry.x = _W/1.6; retry.y = _H/2;
retry.xScale = .7; retry.yScale = .7;
localGroup2:insert(retry)
retry.scene = “level1”

retry:addEventListener(“touch”, changeScene)

----------------Change Scene Director Class Code-----------------------------------
function changeScene(e)
if(e.phase == “ended”) then
director:changeScene(e.target.scene);
end
end[/lua] [import]uid: 29181 topic_id: 9423 reply_id: 309423[/import]

hey ninjapig123,

are you using director class ver. 1.2? If you are, then you need a
loading.lua.

for example:

–assuming you’re on level1.lua and you want to go back to level1.lua then do this

level1.lua —> loading.lua —> back to level1.lua

–if you’re in mainmenu then do this

mainmenu.lua —> loading.lua —> level1.lua

–if you’re going from level1.lua to level2.lua then do this

level1.lua —> loading.lua —> level2.lua

*Note: the tricky part is inside the loading.lua

Check out my game:
Touch Cannon – a **FREE** game
please rate :slight_smile:
[import]uid: 12455 topic_id: 9423 reply_id: 34463[/import]

Yeh I tried making a loading screen but it failed epic-ly. How do you do it? What is the code? Could you post it on this forum topic please? [import]uid: 29181 topic_id: 9423 reply_id: 34490[/import]

Hi ninjapig,

While I do not know a great answer to the question itself, an example of sample code with loading screen implementation, and what I think you might be after is the Ghost vs. Monsters game from Beebee games.

They have an example of this loading screens as was mentioned, and overall you’ll probably find the other parts useful as well.

You can find it in the code exchange under the same name. It’s in the Top Rated list.

Or here’s the direct link

http://developer.anscamobile.com/code/ghosts-vs-monsters [import]uid: 50045 topic_id: 9423 reply_id: 34498[/import]

This is what I used. Hopefully, it will be of used to you.
Note: I used some sqlite3 in my game so please read the note below. This entire code might not work for your game.

[lua]module(…, package.seeall)

– Main function - MUST return a display.newGroup()
local localGroup = display.newGroup()
function new()

local game = require(“beebegames”)
local theTimer
local loadingText

loadingText = game.newRetinaText( “”, 10, 300, “Marker Felt”, 16 )
loadingText:setTextColor( 255, 255, 255, 255 ) --> white
loadingText.text = “Loading…”
loadingText.xScale = 0.7; loadingText.yScale = 0.7 --> for clear retina display text
loadingText.x = 420
loadingText.y = 303

localGroup:insert(loadingText)

local goToLevel = function()

if _G.newGame then

director:changeScene( “level1”, “crossfade”)
print(“new level”)

elseif not _G.newGame then

print(“continue level”)

– this will not work if you don’t store your data inside a sqlite3 database
– I can go into sqlite3 on how to get this done,
– but you should be able to find some info about it on this forum somewhere
– that is something you’ll have to worry about it later too. :slight_smile:
local continueLevel = (settings:loadVar(“level”))

director:changeScene(continueLevel, “crossfade”)
end
end

theTimer = timer.performWithDelay( 1000, goToLevel, 1 )
end

clean = function()
if theTimer then timer.cancel( theTimer ) end

end

– MUST return a display.newGroup()
return localGroup
end [import]uid: 12455 topic_id: 9423 reply_id: 34501[/import]

2 questions.

1: what code are you requiring?

2: what portion of the code won’t work without the lite thing.

I just need the most basic change scene function I can get. Will it work if I just set up a timer that then calls the change scene function? [import]uid: 29181 topic_id: 9423 reply_id: 34503[/import]

Here is, off th etop of my head, a minimal module / scene that you can use as an intermediate for reloading the same scene:

[code]module(…, package.seeall)
local group = display.newGroup()
local bg = display.newImage(“bg.png”)
group:insert(bg)

local function nextScreen()
director.useScene(“your-level”)
end

function new()
timer.performWithDelay(2000, nextScreen) – Set up a one-shot timer to trigger the next screen
return group
end
[/code]Just make sure the delay in the timer is a safe amount longer than the time taken for the director transitions. [import]uid: 46639 topic_id: 9423 reply_id: 34506[/import]

Connection problems - apologies for the double post.
[import]uid: 46639 topic_id: 9423 reply_id: 34507[/import]

Awesome thanks! Just what I needed! [import]uid: 29181 topic_id: 9423 reply_id: 34567[/import]

Guys none of the code that you guys posted works. I modified it to try to make it work…but nothing! Please, I need your help. [import]uid: 29181 topic_id: 9423 reply_id: 34632[/import]

Then you’ll have to post more code, because it *should* work, I can only assume something in your code is causing the problem - its not director. [import]uid: 46639 topic_id: 9423 reply_id: 34720[/import]

@ninjapig,
most of the suggestions here have told you to change the scene from the current level to a intermediate scene and then back to the level. Which is one way to achieve what you want.

The other option is when you write code, write code in a way that the level can be reused, in the sense, when you start the level using new(), call a function called restartGame() that shall reset everything that the level requires, so in the replay/retry game, you call the restartGame() instead of the new() or changing scenes.

This is the way that most games are generally built (using good practices).

Cheers,

?:slight_smile: [import]uid: 3826 topic_id: 9423 reply_id: 34726[/import]

Oh alright thanks Jay! Ill try that and get back to you weither or not that works. [import]uid: 29181 topic_id: 9423 reply_id: 34731[/import]