Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Freydall on Mon 23/01/2006 22:08:10

Title: More than one Idle Animation
Post by: Freydall on Mon 23/01/2006 22:08:10
I've checked the manual and it doesn't say anything about using more than one idle animation. How and where does one put the script for three different idle animations chosen at random by the computer?
Title: Re: More than one Idle Animation
Post by: monkey0506 on Mon 23/01/2006 22:35:12
int rand = Random(2);
if (rand == 0) Character.IdleView = 3;
else if (rand == 1) Character.IdleView = 5;
else if (rand == 2) Character.IdleView = 17;


Replace Character with the character's script o-name (such as cEgo), or a pointer to a character (such as character[5], player, or a custom defined Character* (http://americangirlscouts.org/agswiki/index.php/Scripting%2C_Code_%26_Interaction#AGS_Pointers_for_Dummies_.28A_reference_for_the_rest_of_us.21.29)).
Title: Re: More than one Idle Animation
Post by: Ashen on Mon 23/01/2006 22:52:48
Character.IdleView is read only- to set the view, use Character.SetIdleView(view, delay).

As to where it should go - it depends when you want the idle anim to be changed. One way would be to use a Timer to change it every few seconds (more than the delay, though - otherwise it would never be run).
Title: Re: More than one Idle Animation
Post by: monkey0506 on Mon 23/01/2006 23:12:18
Well that's why it's called pseudo-code.  And RTFM (directed at me and freydall). :=
Title: Re: More than one Idle Animation
Post by: Freydall on Tue 24/01/2006 16:42:12
I don't want the idle animation to be 'changed' because I don't want there to be a specific animation that it is changed from. I want to add a bit of colour to the game by having three different idle animations so you won't see the same old boring one every 15 or 20 seconds. I want the computer to choose one out of the three animations and play it when the idle animation is due. It would just make the game more interesting. So where would I put the script?
Title: Re: More than one Idle Animation
Post by: Ashen on Tue 24/01/2006 16:52:29
By 'changed', I meant, when do you want the random anim to be selected. So would once the current one has been run be OK?

Try something like:

//Top of global script
bool IdleSet;


// repeatedly_execute
if (player.View == player.IdleView) IdleSet = true;
else { // i.e. Not Idle view
  if (IdleSet == true) {
    int rand = Random(2);
    if (rand == 0) Character.SetIdleView(3, 15);
    else if (rand == 1) Character.SetIdleView(5, 15);
    else if (rand == 2) Character.SetIdleView(17, 15);
    IdleSet = false;
  }
}


You could also vary the delay, using something like 12+Random(8 ) to give a delay between 12 and 20 seconds. Also, Akumayo's Advanced Randoms (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=23175.0) module could cut those conditions down.
   
 
Title: Re: More than one Idle Animation
Post by: Freydall on Tue 24/01/2006 17:10:56
It comes up with an error message on the first line. It doesn't understand the term bool. (Parse error: unexpected 'bool')
Title: Re: More than one Idle Animation
Post by: Ashen on Tue 24/01/2006 17:31:04
It should work OK. Where exactly have you put it? (Also, what version are you using?)
Alternatively, change it to an int, and check/set numeric values for it, instead of true/false.
Title: Re: More than one Idle Animation
Post by: Freydall on Tue 24/01/2006 17:40:37
I put it right at the top of the Global script and I'm using version 2.62.
Title: Re: More than one Idle Animation
Post by: Khris on Tue 24/01/2006 17:43:30
Ashens script uses 2.7.x code. I would recommend switching to the newest version.
Title: Re: More than one Idle Animation
Post by: Ashen on Tue 24/01/2006 17:45:11
There's the problem - AFAIK, 2.62 doesn't have the bool type, so make it an int and you'll be OK.
You'll also need to change the rest of the scripting, to use 2.62 commands. Change Character.SetIdleView(..) commands to SetCharacterIdle(char, view, delay).

And yes, updating to the newest version (or at least a newer version) is advisable.
Title: Re: More than one Idle Animation
Post by: Freydall on Tue 24/01/2006 17:59:23
I just upgraded to version 2.7 and unfortunately there are still more problems. This time the bool works but now it says (Parse error: unexpected 'if')
Title: Re: More than one Idle Animation
Post by: Ashen on Tue 24/01/2006 18:04:26
What line is the error on, and what function is it in?
Title: Re: More than one Idle Animation
Post by: Freydall on Tue 24/01/2006 18:07:12
On line 5.

01|  // main global script file
02|  bool IdleSet;
03|
04|  // repeatedly_execute
05|  if (player.View == player.IdleView) IdleSet = true;
06|  else { // i.e. Not Idle view
07|    if (IdleSet == true) {
08|      int rand = Random(2);
09|      if (rand == 0) cLig.SetIdleView(25, 15);
10|      else if (rand == 1) cLig.SetIdleView(26, 15);
11|      else if (rand == 2) cLig.IdleView(27, 15);
12|      IdleSet = false;
13|    }
14|  }
Title: Re: More than one Idle Animation
Post by: Ashen on Tue 24/01/2006 18:08:55
Everything past line 4 ( the if .. else statements) needs to be in the repeatedly_execute function, rather than at the top of the global script.
Title: Re: More than one Idle Animation
Post by: Freydall on Tue 24/01/2006 18:11:07
Okay, thanks for getting me this far but now it gets confused when I put cLig as the script o-name instead of "Character", even though it says that that is the script o-name on the characters page.


// main global script file
bool IdleSet;

// repeatedly_execute
function repeatedly_execute () {
if (player.View == player.IdleView) IdleSet = true;
else { // i.e. Not Idle view
  if (IdleSet == true) {
    int rand = Random(2);
    if (rand == 0) cLig.SetIdleView(25, 15);
    else if (rand == 1) cLig.SetIdleView(26, 15);
    else if (rand == 2) cLig.IdleView(27, 15);
    IdleSet = false;
    }
  }
}

It says:

Error (line 12): PE04: parse error at 'cLig'
Title: Re: More than one Idle Animation
Post by: Ashen on Tue 24/01/2006 18:38:18
It should be:
else if (rand == 2) cLig.SetIdleView(27, 15);

Sorry, typo when I first posted the code ... Erm, I mean I was testing you. Yes, that's it.
Title: Re: More than one Idle Animation
Post by: Freydall on Tue 24/01/2006 18:51:33
Thanks everyone... this is now SOLVED.