Changing to a Random Scene

sdparduesdpardue Member Posts: 110
edited November -1 in Working with GS (Mac)
Here's the issue:

I have 5 scenes with games/puzzles that I want to display in random order, displaying all 5 of the scenes, with no scene displayed twice.

Each scene has a boolean attribute (for example game.Scene1Played) that indicates whether it has been displayed. All 5 attributes are initially set to False.

To select the first scene, i generate a number that I store in an attribute game.NextScene using random(1,5). Then, if game.NextScene=1, I change scene to Scene1, if game.NextScene=2, change scene to Scene2… etc. It's easy to select the first one to display, since none of the 5 have yet been displayed.

Where I have the problem is in how to select the 2nd through 5th random scene.

Upon the user clicking an arrow button, I generate another random number with random(1,5) and if that scene hasn't been played, then i change scene to that scene. But if it HAS already been played, I need to keep generating random numbers until I find one that hasn't been played.

Without some sort of WHILE loop mechanism, I can't figure out how to keep generating random numbers until I find a non-played scene. (BTW, I first check to see if they've all been played and go to a "Finished" scene.)

Has anyone been able to figure out how to simulate some sort of looping structure for rules? Or maybe limit a group of non-continuous numbers from which I can randomly pick one? Or another way to do this? While it's just 5 scenes at this point, I can envision selecting random scenes from a larger number.

Thanks,

Steve

Comments

Sign In or Register to comment.