Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Wed 17/10/2012 16:23:09

Title: SOLVED: Random int if animation frame=2
Post by: Slasher on Wed 17/10/2012 16:23:09
SOLVED: CHECK DOWN

Need a small hand on this script.

An animation plays eRepeat, eNoBlock.

Depending on that animations loop frame events should happen at random.

It is not Timer based.

There are 3 options at random.

Here is what I have:

Top of room script: int ran=2;

Code (AGS) Select
function room_RepExec()
{

ran++;
ran=Random(2);

if  (cwitchey.View==90  && cwitchey.Loop==0 && cwitchey.Frame==2) // Then 3 options if animation at frame 2
 
if  (ran==0)
{
   // Do this
}
else if  (ran==1)
{
  // Do this

else if  (ran==2)
{
   // Do this
}
}


So far it does frame 2, shows an option (which has a delay of 50) and then the animation stops.

I am looking at adding if frame 5 as well.

all help much appreciated

EDIT

This seems to do the trick:

Code (AGS) Select
function room_RepExec()
{
ran++;
ran=Random(2);

if  (cwitchey.View==90 && cwitchey.Loop==0 && cwitchey.Frame==2)
{
if(ran==0)
{
  cELF.Say("Hello 1");
  cELF.Say("Hello 1 again");
}
else if(ran==2)
{
cELF.Say("Hello 2");
cELF.Say("Hello 2 again");
}
  else
{
cELF.Say("Hello 3");
cELF.Say("Hello 3 again");
}
}
}


I also want to declare:
if cElf >=250 give 3 options and also if <=251 give 3 options

Can you help please

EDIT EDIT EDIT This seems to have solved the case:

Code (AGS) Select
function room_RepExec()
{

ran++;
ran=Random(2);

if  (cwitchey.View==90 && cwitchey.Loop==0 && cwitchey.Frame==2 )
{
if(ran==0 && cELF.y >=251 )
{
  cELF.Say("Hello 1");
  cELF.Say("Hello 1 again");
}
else if(ran==0 && cELF.y <=250 )
{
  cELF.Say("Hello 1");
  cELF.Say("Hello 1 again");
}
else if(ran==1 && cELF.y >=251 )
{
cELF.Say("Hello 2");
cELF.Say("Hello 2 again");

}
else if(ran==1 && cELF.y <=250 )
{
cELF.Say("Hello 2");
cELF.Say("Hello 2 again");

}
else if(ran==2 && cELF.y >=251 )
{
cELF.Say("Hello 3");
cELF.Say("Hello 3 again");

}
else if(ran==2 && cELF.y <=250 )
{
cELF.Say("Hello 3");
cELF.Say("Hello 3 again");
}
}
}
Title: Re: SOLVED: Random int if animation frame=2
Post by: Andail on Thu 18/10/2012 08:57:31
Can you explain this part to me (line 4 and 5):

ran++;
ran=Random(2);

You first set ran to increase repeatedly, immediately followed by setting it to 0, 1 or 2 randomly?
Title: Re: SOLVED: Random int if animation frame=2
Post by: Slasher on Thu 18/10/2012 10:02:36
Hi

I copied an old script and forgot to take out :) (roll)