Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: slufan on Sun 08/12/2019 17:25:22

Title: Mutiple views for the same action? [SOLVED]
Post by: slufan on Sun 08/12/2019 17:25:22
Hello Everyone,

It's there posible to have more than a view to do the same action?
I know that AGS have ChangeView() and LockView() functions, but when I try to change the view and use Character.say() AGS always play the standard view defined for Talk.
What I try to do is this.

Say with standard animation                                Say with a second animation                               Say with a third animation
(https://i.imgur.com/wNYKWkQ.gif)                                                             (https://i.imgur.com/42ziSr4.gif)                                                   (https://i.imgur.com/wwAxV7z.gif)

Thanks in advance.
Title: Re: Mutiple views for the same action?
Post by: Haggis on Sun 08/12/2019 17:45:45
It's been a long time since I did any AGS coding - but characters have idle views and speech views. Without seeing your code I wouldn't know which you've tried changing before the dialogue, but I would have thought you could change the character 'speech view' to a random number before the dialogue in question?

EDIT - to add clarity to the above - you would create a view for each speech animation, then prior to the dialogue starting you would generate a random number, which would set the character speech view to one of your various speech views.
Title: Re: Mutiple views for the same action?
Post by: Crimson Wizard on Sun 08/12/2019 17:54:35
Character.ChangeView is for the standing/walking animation.
Character.IdleView is for random idling animation when character does not move for some time.
Character.LockView is for the any custom animation that you control yourself (via Character.Animate)
Character.SpeechView is for speech animation.
Character.BlinkView is for portrait blinking animation with Sierra style speech.
Character.ThinkView is for when you call Character.Think().
Title: Re: Mutiple views for the same action?
Post by: Khris on Sun 08/12/2019 23:33:17
SpeechView is a property btw, so you need something like
Code (ags) Select
  player.SpeechView = INDY_TALK3;
Title: Re: Mutiple views for the same action?
Post by: slufan on Sun 08/12/2019 23:41:28
Well lets see if I can explain myself a little bit more, my English is not as good as I would like... Google helps, but not to much  :embarrassed:

Quote from: Haggis on Sun 08/12/2019 17:45:45
EDIT - to add clarity to the above - you would create a view for each speech animation, then prior to the dialogue starting you would generate a random number, which would set the character speech view to one of your various speech views.

Yes Haggis, I have the "standard" animation for the character when he talks, but I want change the animation depends the situation or who he is talking to.
I have created 2 new views with the second and the third animation. The normal animation is the first in my first post, so when my character talks with other the animation plays correctly.


Code (ags) Select

cCharacter.Walk(12, 84, eBlock, eWalkableAreas);
cCharacter.Say("Hello, who are you?");


But in certain situations or depending on who you are talking to, I want to change the animation of speaking to one of the other two, so  I add before my character talks this:
Code (ags) Select

cCharacter.Walk(12, 84, eBlock, eWalkableAreas);
cCharacter.ChangeView(2); //for the second animation or 3 for the third animation
cCharacter.Say("Hello, who are you?");


The problem is that AGS still talk with the animation defined in Character SpeechView. If I use the Character.LockView() and Character.Animate() functions to change the animation, depends on the parameters I use in Character.Animate() makes one thing or another.
Code (ags) Select

cCharacter.Walk(12, 84, eBlock, eWalkableAreas);
cCharacter.Lock(2); //for the second animation or 3 for the third animation
cCharacter.Animate(2, 0, 5, eBlock, eForwards); // with this first play the animation and then speak
cCharacter.Animate(2, 0, 5, eNoBlock, eForwards); // with this play the first frame of the animation, stop it, and then speak
cCharacter.Say("Hello, who are you?");
cCharacter.UnlockView(); //returns to NormalView


If you need any more information please ask for it and I will try to provide it.
Thanks.

Title: Re: Mutiple views for the same action?
Post by: Cassiebsg on Mon 09/12/2019 00:26:56
You do not want this:
Quote
cCharacter.ChangeView(2); //for the second animation or 3 for the third animation

Because ChangeView is for changing the standing/walking animation as CW pointed out.

What you want is what Khris wrote, since you want to change the Speech View!  :)

Also, since this is kind of a pain to do every single time you wish to change the speech view, I would advise you to create a custom function and use it instead of the normal Say.

So that instead of character.Say, you could type something like:

MySay("Hello, who are you?", vINDY_TALK3);



Title: Re: Mutiple views for the same action?
Post by: slufan on Mon 09/12/2019 10:48:45
Thanks Cassiebsg but, how can I make this?
Title: Re: Mutiple views for the same action?
Post by: Laura Hunt on Mon 09/12/2019 11:22:17
Quote from: slufan on Mon 09/12/2019 10:48:45
Thanks Cassiebsg but, how can I make this?

Look for "extender functions" in the manual, it's all explained there :)
Title: Re: Mutiple views for the same action?
Post by: Cassiebsg on Mon 09/12/2019 13:48:45
Also, searching for it on this forum section, will give you some good relevant topics to look into.
Here's one of them: https://www.adventuregamestudio.co.uk/forums/index.php?topic=54943.msg636564220#msg636564220

Reason I didn't give code, is that I can't actually code out of the blue. I  often see how I've done it before, use the great auto-completion of AGS and read the manual. And I didn't had the time to give you code last night. But I guarantee you that it's worth digging into it, learning and understanding how they work. You are sure to more often than not to use this as it saves soooo much code and makes you script easier to read.
Check the manual, check a couple of the help threads on the forum, and try it out. And if you still need help after it, just ask again. :)
Title: Re: Mutiple views for the same action?
Post by: slufan on Mon 09/12/2019 15:35:28
Thanks for the responses, I'll take a look to the post and the "extender functions" in the manual and, if at last, can't make it the solution provided by Khris works fine, so add a few lines of code to the script is not a great problem.
Title: Re: Multiple views for the same action?
Post by: Khris on Mon 09/12/2019 15:45:03
Here's the basic idea:

Code (ags) Select
// add to global script header

import void MySay(this Character*, String message, int speech_view = 0);


Code (ags) Select
// add to top of global script

void MySay(this Character*, String message, int speech_view) {
  if (speech_view > 0) this.SpeechView = speech_view;
  this.Say(message);
}


The import line sets the last argument to be optional and its default value to 0, omitting it will therefore simply keep the current SpeechView.
So now you can do something like:

Code (ags) Select
  player.MySay("Hello.");

  player.MySay("What?", INDY_TALK_ANGRY);  // switch to new speech view for this line
  player.MySay("Why would you do that!?");  // keep using INDY_TALK_ANGRY

  player.MySay("I see. Ok then.", INDY_TALK); // back to normal view for this line


A different approach is to create an extender function for each talk view so you can use "verbs":
Code (ags) Select
  cIndy.Exclaim("What!?"); // uses INDY_TALK_LOUD
  cIndy.Say("Oh.");  // uses regular talk view
  cIndy.Flail("That's what I meant!"); // uses INDY_TALK_ARMS
Title: Re: Mutiple views for the same action?
Post by: slufan on Tue 10/12/2019 11:42:54
Thank you Khris, you are the best.