[SOLVED] Help having random scene?

Hello

I am trying to figure out how to have my screen swap to random instead of going to the next scene have it switch scene 1 instead of 2.

Example: I have finished scene 1 instead of going to scene 2 I want it to go to scene 3 or 9 or 14 not in order but as random.

How would that function look? [import]uid: 17058 topic_id: 30474 reply_id: 330474[/import]

variable = random
gotoscene(variable) [import]uid: 116842 topic_id: 30474 reply_id: 122084[/import]

Well, a little more in depth is you would probably want to put your scene names in a table, and then you can do something like

[lua]local mySceneTable = {“scene1”, “scene2”, “scene3”}

function randomScene()
storyboard.gotoScene(mySceneTable[math.random(1, table.getn(mySceneTable))];
end[/lua]

might need to make some adjustments but it’s the basic idea. [import]uid: 147305 topic_id: 30474 reply_id: 122087[/import]

Hey @budershank thanks a lot I just got it and fixed the mistake you had it was minor I did mines like this

local mySceneTable = {"scene1", "scene2", "scene3"}  
  
local square = display.newRect(0,0,50,50)  
square.x = 240  
square.y = 160  
square:setFillColor(255,0,0)  
localGroup:insert(square)  
   
function randomScene()  
director:changeScene(mySceneTable[math.random(1, table.getn(mySceneTable))])  
end  
square:addEventListener("touch", randomScene)  

It still worked like this. The extra code is for people that want to know how it looks [import]uid: 17058 topic_id: 30474 reply_id: 122155[/import]

variable = random
gotoscene(variable) [import]uid: 116842 topic_id: 30474 reply_id: 122084[/import]

Well, a little more in depth is you would probably want to put your scene names in a table, and then you can do something like

[lua]local mySceneTable = {“scene1”, “scene2”, “scene3”}

function randomScene()
storyboard.gotoScene(mySceneTable[math.random(1, table.getn(mySceneTable))];
end[/lua]

might need to make some adjustments but it’s the basic idea. [import]uid: 147305 topic_id: 30474 reply_id: 122087[/import]

Hey @budershank thanks a lot I just got it and fixed the mistake you had it was minor I did mines like this

local mySceneTable = {"scene1", "scene2", "scene3"}  
  
local square = display.newRect(0,0,50,50)  
square.x = 240  
square.y = 160  
square:setFillColor(255,0,0)  
localGroup:insert(square)  
   
function randomScene()  
director:changeScene(mySceneTable[math.random(1, table.getn(mySceneTable))])  
end  
square:addEventListener("touch", randomScene)  

It still worked like this. The extra code is for people that want to know how it looks [import]uid: 17058 topic_id: 30474 reply_id: 122155[/import]