Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: CB.. on Tue 21/10/2003 01:36:53

Title: using more than 3 random -ifs;else ifs;?
Post by: CB.. on Tue 21/10/2003 01:36:53
the reference manual gives the code for scripting a random script as

int ran=Random(2);
if (ran==0) NewRoom(1);
else if (ran==1) NewRoom(2);
else NewRoom(3);



but implys that more than three "ifs /else/else ifs" can be added

but im not sure how to add the extra randomisations
how would i script more than these three in the same script?

i want to script a random response on the basis of a dice throw , so i need six options in the same randomisation

and more if i can have them (for perhaps a full deck of cards)
Title: Re:using more than 3 random -ifs;else ifs;?
Post by: scotch on Tue 21/10/2003 03:13:25
if you just want to add more ifs to the end of that script you can do so just by adding another 'else if'

else if (ran==2).....
else if (ran==3)....

but that only makes sense if ran could actually be 2 or 3 or so on, so you have to change the line
int ran=Random(2);
to...
int ran=Random(51);

that is if you were trying to pick a random card from a deck of 52 (the random result will start from 0, rather than 1 so the number in the random should be one less than the number of possible results you want)



For your dice script that would be something like this:

int sideresult=Random(5);
if(sideresult==0) Display("You rolled a 1.  You lose!");
else if(sideresult==1) Display("You rolled a 2.  You lose!");
else if(sideresult==2) Display("You rolled a 3.  You lose!");
else if(sideresult==3) Display("You rolled a 4.  Not quite enough, you lose!");
else if(sideresult==4) Display("You rolled a 5.  So close, but you lose!");
else Display("You rolled a 6.  You are win!");
Title: Re:using more than 3 random -ifs;else ifs;?
Post by: CB.. on Tue 21/10/2003 12:02:47
many thanks

yup that works a treat !