I would like a script that would accomplish the following:
Get a random number between 0 and 3
if the number is 0 go to room 6
if the number is 1 go to room 7
if the number is 2 go to room 8
Thanks for any help
You could've found something regarding your problem in the ags manual.
Anyways, here we go:
if (random(2) == 0) // if a random number between 0 and 2 is 0
NewRoom (6); // then go to room 6
else if (random(2) == 1) // if the random number is 1
NewRoom (7); // then go to room 7
else if (random(2) == 2) // if the random number is 2
NewRoom (8); // then go to room 8
That's about it. Ask if you have questions.
Each time you call the Random() function, a new random number is generated, so with your code it's possible the room doesn't change at all.
Better do:
int ran = Random(2); // generate random number between 0 and 2
if (ran == 0) // if number is 0
NewRoom(6); // go to room 6
else if (ran == 1) // if number is 1
NewRoom(7); // go to room 7
else if (ran == 2) // if number is 2
NewRoom(8); // go to room 8
Oh, I was wondering about that. Thank you, Strazer. That just pointed my nose towards a major bug in "Troopers".
I feel obliged to give a more elegant way of doing it:
NewRoom(Random(2) + 6);