Calling a scene over and over from itself?

I have question about calling a scene from storyboard - using the same scene to reload itself.

I am still playing around with Corona and the first app I am writing is a simple trivia game.

I have a main.lua and gamescene.lua. Before going to gamescene.lua, I am setting up an table with 5 questions. When I get to gamescence.lua it loads the first value in the table. I also have a handler for the user selection of a right or wrong answer where I increment the counter for the table. After the user selects either one I wanted to reload the scene I am currently on with new data. Whats the best way to do this? I have tried a couple of different things but I haven’t had any success.

Is the best thing to do here, remove everything from the scene (all the display objects) and call the enterScene method again?

I haven’t found anything on this yet. Any thoughts on how to do something like this? [import]uid: 124716 topic_id: 27082 reply_id: 327082[/import]

What exactly do you update? The score obviously, but what else? Do you change images or just text? [import]uid: 52491 topic_id: 27082 reply_id: 109979[/import]

I will just be changing text for the question and for the answers.

Basically in my right and wrong answer handlers I was calling a function “nextQuestion” that was going to increment my array count, and then I wanted to reload the game scene. I was trying to call the createScene method again and I also tried storyboard.gotoScene.

Hopefully that is enough information.

Thanks! [import]uid: 124716 topic_id: 27082 reply_id: 110004[/import]

You could purge and reload the scene, although you could also simply remove and recreate the text - the reason this might be a better option is because reloading the scene means reloading all the graphics, not only the ones you need to reload.

Example;

[lua]–You’d load all graphics here, I’m just doing a background for the tap event
local bg = display.newRect( 0, 0, 320, 480 )
bg:setFillColor(50,100,255)

–Variable so you know what Q you are on
local upTo = 1

–All your question texts
local myQs = {
“this is 1”,
“this is 2”,
“this is 3”,
“this is 4”
}

–Display initial question
local qText = display.newText(myQs[upTo], 10, 10, native.systemFont, 16)

–Function for next question, would also contain info to update score etc.
local function nextQuestion()
upTo = upTo + 1
qText.text = myQs[upTo]
end
bg:addEventListener(“tap”, nextQuestion)[/lua]

That will run through the questions when you tap the background although you’d likely have the listener on buttons instead. You’d also include logic to adjust the score.

But that should give you a good example of updating text without having to reload the scene - see what you think.

Peach :slight_smile: [import]uid: 52491 topic_id: 27082 reply_id: 110083[/import]