Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: subspark on Sun 08/11/2009 12:03:51

Title: How to code random play of sprite animation [Solved]
Post by: subspark on Sun 08/11/2009 12:03:51
Hey folks. I'm trying to create a repeating random timer that runs the following code anywhere between 45 to 70 seconds each time.
oIdol.SetView(IDOL_SPARKLE, 0, 0);
oIdol.Animate(0, 1, eOnce, eNoBlock);


I must admit I'm a little clueless on how to approach this.

Cheers,
Sparky.
Title: Re: How to code random play of sprite animation
Post by: NsMn on Sun 08/11/2009 12:05:22
To get a random value between two values, use, e.g.:
Random(10)+10;

This will return a value between 10 and 20.
Title: Re: How to code random play of sprite animation
Post by: subspark on Sun 08/11/2009 12:13:47
Thanks, I already know that. However I have no clue how to incorporate a timer into this which activates the animation of my sprite. I've explained it better above.

Cheers,
Sparky.
Title: Re: How to code random play of sprite animation
Post by: NsMn on Sun 08/11/2009 12:24:43

function repeatedly_execute(){
if(IsTimerExpired(10)==1 && oIdol.Animating==false){
   oIdol.SetView(IDOL_SPARKLE, 0, 0);
   oIdol.Animate(0, 1, eOnce, eNoBlock);
   SetTimer(10,0);
}
if(IsTimerExpired(10)==0 && oIdol.Animating==false)SetTimer(10,Random(25)+45);
}

Title: Re: How to code random play of sprite animation
Post by: Khris on Sun 08/11/2009 14:33:42
This should suffice:

function repeatedly_execute() {
  if (IsTimerExpired(10)) {
    oIdol.SetView(IDOL_SPARKLE, 0, 0);
    oIdol.Animate(0, 1, eOnce, eNoBlock);
    SetTimer(10,Random(25)+45)
  }
}


To start the sequence, set the timer in after_fadein.
Title: Re: How to code random play of sprite animation
Post by: subspark on Sun 08/11/2009 18:19:21
Thanks guys, You rock!  8)

Cheers,
Sparky.