More than one Idle Animation

Started by Freydall, Mon 23/01/2006 22:08:10

Previous topic - Next topic

Freydall

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?
AEscplega is the best epic ever. Chapter I is finally finished and Chapter II is on it's way.

monkey0506

Code: ags
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*).

Ashen

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).
I know what you're thinking ... Don't think that.

monkey0506

Well that's why it's called pseudo-code.  And RTFM (directed at me and freydall). :=

Freydall

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?
AEscplega is the best epic ever. Chapter I is finally finished and Chapter II is on it's way.

Ashen

#5
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:
Code: ags

//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 module could cut those conditions down.
   
 
I know what you're thinking ... Don't think that.

Freydall

#6
It comes up with an error message on the first line. It doesn't understand the term bool. (Parse error: unexpected 'bool')
AEscplega is the best epic ever. Chapter I is finally finished and Chapter II is on it's way.

Ashen

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.
I know what you're thinking ... Don't think that.

Freydall

I put it right at the top of the Global script and I'm using version 2.62.
AEscplega is the best epic ever. Chapter I is finally finished and Chapter II is on it's way.

Khris

Ashens script uses 2.7.x code. I would recommend switching to the newest version.

Ashen

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.
I know what you're thinking ... Don't think that.

Freydall

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')
AEscplega is the best epic ever. Chapter I is finally finished and Chapter II is on it's way.

Ashen

What line is the error on, and what function is it in?
I know what you're thinking ... Don't think that.

Freydall

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|  }
AEscplega is the best epic ever. Chapter I is finally finished and Chapter II is on it's way.

Ashen

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.
I know what you're thinking ... Don't think that.

Freydall

#15
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'
AEscplega is the best epic ever. Chapter I is finally finished and Chapter II is on it's way.

Ashen

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.
I know what you're thinking ... Don't think that.

Freydall

Thanks everyone... this is now SOLVED.
AEscplega is the best epic ever. Chapter I is finally finished and Chapter II is on it's way.

SMF spam blocked by CleanTalk