Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: thealexv2 on Sat 07/08/2010 10:09:46

Title: Help with the random function
Post by: thealexv2 on Sat 07/08/2010 10:09:46
whenever my main character is attacked by the villain i want a 50% chance that the character will live or die. i have been able to do this but there is a problem. the random function gives me  5 possibilites instead of 2. i am not sure what i am doing wrong.  The first view is the death animation and the second is the hurt. my script is this:
int i;
i = random(1);
if (i == 0) player.lockview(13); 
player.animate(0, 7, eonce,enoblock, eforwards);
wait(50);
display("Lily is dead");
resetroom(1);
if (i == 1) player.lockview(15);
please respond, and thanks for reading
Title: Re: Help with the random function
Post by: Matti on Sat 07/08/2010 10:32:12
What are the five possibilities ??

Does this piece of code run more than once, unintentionally?
Title: Re: Help with the random function
Post by: Wyz on Sat 07/08/2010 11:04:29
Use brackets like:


int i = random(1);
if (i == 0)
{
player.lockview(13); 
player.animate(0, 7, eonce,enoblock, eforwards);
wait(50);
display("Lily is dead");
resetroom(1);
}
else
player.lockview(15);
Title: Re: Help with the random function
Post by: Matti on Sat 07/08/2010 12:44:55
Ah, right. I must be tired.

*drinks some more coffee*