Different Answers. Same Switch

So what i am using is a program called gamemaker studio. The language is very C++ oriented so excuse the slightly different syntax, but if you answer in C++ I will know exactly what you mean.

Now on to the question. So in this game there are 5 lanes. I want 2-4 asteroids to appear in 2-4 different lanes. The openspot variable is the X axis in the game and the switch will set the asteroid to different lanes. How do I get the switch to chose a different case every time it loops? If it chooses case 3 by random, how do I get 0,1,2,4 to be only ones left?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
for(astroidAmount = irandom(2);astroidAmount >= 0;astroidAmount--)
{
global.openspace = irandom(4)
switch (global.openspace)
{
    case 0:
    {
    openspot = 30
    }
    case 1:
    {
    openspot = 60;
    }
    case 2:
    {
    openspot = 90;
    }
    case 3:
    {
    openspot = 120;
    }
    case 4:
    {
    openspot = 150
    }
}//end switch

}//end for loop 


irandom is a random number 0- set number
Last edited on
Your problem boils down to having n unique random numbers in the range 0-4, so push_back() these numbers into a std::vector<int> and std::shuffle() the vector, then you can choose any three of the vector's cells as your lanes
Topic archived. No new replies allowed.