Also, if you’re using Composer (or really any Lua module would have the same issue), your shuffling code may not be re-executed.
In Lua, modules when they are first required has the code in the main chunk of the module executed. After that, when you require the module a second time, you only get a reference to the object that was returned from the first loading. Thus if you have a module like:
local M = {} math.randomseed( os.time() ) local function shuffleTable( t ) local rand = math.random assert( t, "shuffleTable() expected a table, got nil" ) local iterations = #t local j for i = iterations, 2, -1 do j = rand(i) t[i], t[j] = t[j], t[i] end end M.letters = { "A", "B", "C", "D" } shuffleTable(M.letters) --\<------ assuming you use the code from the shuffle tutorial above return M
No matter how many times you require that module after the first, shuffleTable() will have run just once until the module has been “unrequired” and there is no straight API for doing that. A Composer scene is nothing more than a Lua module with some events and API calls to make scene transitions happen, so it has to obey all the rules for any other Lua scene.
If you have executable code in your Composer scene (not inside a scene:create() or scene:show() function which is called by events outside of the “require”), it gets run once. Because of other the way the scene objects are cached, scene:create() may also not get called every time a scene shows. Resetting scenes frustrates a lot of people trying to learn Composer. Getting your questions reshuffled sounds like it fits into the resetting scene category.
There is a simple way around it, its a brute force method, but it’s simple and it works until scene loading becomes painfully slow. Simply remove the scene before you go to it. From your menu scene, call:
composer.removeScene("yourgamescenename") composer.gotoScene("yourgamescenename", options ) --\<------- whatever options you normally would send, delay, transition, etc.
If you’re not going back to your menu afterwards, go to a cut-scene, i.e. level over, try again, next level, etc. and in that scene, remove the game scene just before you go to it.
You cannot remove the scene you are currently in. Calling composer.removeScene() has to happen in some other scene.
Rob