Random Scene Change Without Repeats

Hello,

With the help of @Bejoy, I managed to change scenes randomly using a director class, but is there any way to do so but without loading the previous screen(without repeats)?

I used this code:

local t = {“Scene1”, “Scene2”, “Scene3”}
local pos = math.random(1,3) – Random value Between 1 and 3
director:changeScene(t[pos])
Thank you. [import]uid: 100216 topic_id: 21479 reply_id: 321479[/import]

To avoid repeats you want a shuffle instead of random.

Check out the following link.

http://www.ludicroussoftware.com/blog/2011/01/07/table-shuffling-in-luacorona/

You can loop the size of the table (#t) and when the reach it reshuffle, may have to check if the new first is the same as the last one.

Hope this helps

[import]uid: 119459 topic_id: 21479 reply_id: 85031[/import]