Random Scene Change

Hello,

I have created a quiz game and all the quiz questions are in separate .lua pages where I am calling the next quiz page by using the director change scene feature.

But is there any way where I can generate the next quiz randomly so that the order of the quizzes does not become obvious.

I have 10 questions. So, instead going from question 1 to question 2, a random question page is called within the available 10 pages.

Thank you in advance. [import]uid: 100216 topic_id: 21471 reply_id: 321471[/import]

@Aakash,
This could be done in several ways. One easy way could be to store the lua class names into an array and then use math.random function to pick up a random scene lua file and pass it to the director class.

  
local t = {"Scene1", "Scene2", "Scene3"}  
local pos = math.random(1,3) -- Random value Between 1 and 3  
director:changeScene(t[pos])  

There could be other ways too. Hope this helps…

thx,
Bejoy [import]uid: 84539 topic_id: 21471 reply_id: 84972[/import]

@bejoy,

Thanks a ton. Was it that simple?
It solved my problem, thank you very much.

I would like to ask you one more thing, if you don’t mind.

For my app, I have used the simple score.lua class from techority to add score and I am also using a global variable to store the score for the next level. But how can I store a high score?

Any help would be appreciated.

And thank you once again. [import]uid: 100216 topic_id: 21471 reply_id: 84975[/import]

@aakash - ur welcome.

Regarding storing, are u referring to keeping the score for the app session or do you want to persist for future use

You could it in the following ways:

  1. Simple easy way, Use a global variable
  2. Use ICE module to persist to the file system. This will be available next time the user starts to play.
    http://developer.anscamobile.com/code/ice
  3. Or better use a sqllite database to store all the scores. Same persistence behaviour as ICE
    thx,
    Bejoy [import]uid: 84539 topic_id: 21471 reply_id: 84981[/import]

Thank you very much. I will give a try with ICE…

Thanks. [import]uid: 100216 topic_id: 21471 reply_id: 84983[/import]

Awesome… this is great. I have a question though. For the random scene, do I need to have the code in EACH of the scene.luas I have, or just main.lua?

Any help would be appreciated. Thanks! [import]uid: 32804 topic_id: 21471 reply_id: 97145[/import]

Actually I would have a table that lists each of your scene names and then run a shuffle function on the table. You can use the forum search box and search on shuffle to get a simple table shuffler function.

Then just loop through the now shuffled table.

Rob [import]uid: 19626 topic_id: 21471 reply_id: 97151[/import]