Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: nightmarer on Sun 12/12/2021 22:22:06

Title: Character.Speaking function during dialog
Post by: nightmarer on Sun 12/12/2021 22:22:06
Hello.
The following code is in global script/execute always function.
It works to create animation for character when you are using mushots aswell, but it is not working when the character speaks inside a dialog,
it seems that the character inside the dialog is not detecting Character.Speaking function.

Code (ags) Select
  if (Sara.Speaking && !Sara.Animating) {
    Sara.ChangeView(242); //Change to speaking animation
    Sara.Animate(Sara.Loop, 3, eRepeat, eNoBlock, eForwards);
  } else if(!Sara.Speaking && Sara.View == 242) {
    Sara.ChangeView(244); //Change back to walk animation
  }


Any idea about how to solve it?
Title: Re: Character.Speaking function during dialog
Post by: arj0n on Sun 12/12/2021 23:58:26
Character.SpeechView?
Title: Re: Character.Speaking function during dialog
Post by: Crimson Wizard on Mon 13/12/2021 02:16:02
First of all, this code looks wrong, because for proper behavior you need to call LockView, not ChangeView, before Animate (and then UnlockView). But I'm not certain what other actions are playing at the same time (are you also playing some portraits simultaneously? if this is what you've meant by "mushots"...)

In any case, my suggestion is to not start animation in the repeatedly_execute, but instead write a custom Say function that runs everything, and use that for speech.

If this is only for particular character / certain moments, then may use this function explicitly in dialogs. But if it's for all the characters in game, set up "Custom Say function in dialog scripts" in General Settings -> Dialog section: then this function will be used instead of Say to replace common dialog lines.

The example of how the function may look like:
Code (ags) Select

function MySay(this Character*, const string text) {
    // Starting up
    int anim_view;
    if (this == Sara) { anim_view = 242; }
    else if (this == SomeoneElse) { anim_view = xxx; } // etc

    // Running speech
    this.LockView(anim_view); // lock to speaking animation
    this.Animate(this.Loop, 3, eRepeat, eNoBlock, eForwards);
    this.Say(text);

    // Ending
    this.UnlockView(); // unlock back to current view
}


Then it may be used like
Code (ags) Select

player.MySay("text");
Sara.MySay("bla bla bla");
Title: Re: Character.Speaking function during dialog
Post by: nightmarer on Mon 13/12/2021 07:14:38
Quote from: Crimson Wizard on Mon 13/12/2021 02:16:02
First of all, this code looks wrong, because for proper behavior you need to call LockView, not ChangeView, before Animate (and then UnlockView). But I'm not certain what other actions are playing at the same time (are you also playing some portraits simultaneously? if this is what you've meant by "mushots"...)
It is running with changeview so far, but I will use lock if it is more correct. I meant "mugshots".

Quote from: Crimson Wizard on Mon 13/12/2021 02:16:02
In any case, my suggestion is to not start animation in the repeatedly_execute, but instead write a custom Say function that runs everything, and use that for speech.

If this is only for particular character / certain moments, then may use this function explicitly in dialogs. But if it's for all the characters in game, set up "Custom Say function in dialog scripts" in General Settings -> Dialog section: then this function will be used instead of Say to replace common dialog lines.

The example of how the function may look like:
Code (ags) Select

function MySay(this Character*, const string text) {
    // Starting up
    int anim_view;
    if (this == Sara) { anim_view = 242; }
    else if (this == SomeoneElse) { anim_view = xxx; } // etc

    // Running speech
    this.LockView(anim_view); // lock to speaking animation
    this.Animate(this.Loop, 3, eRepeat, eNoBlock, eForwards);
    this.Say(text);

    // Ending
    this.UnlockView(); // unlock back to current view
}


Then it may be used like
Code (ags) Select

player.MySay("text");
Sara.MySay("bla bla bla");

Thanks for the suggestion. I didn't know it was possible to set a custom dialog script.
Title: Re: Character.Speaking function during dialog
Post by: nightmarer on Mon 13/12/2021 15:14:07
Hello.
This script is not working. I have identified that the character is not being identified through the dialog.
Following your code I entered some more information for a few characters more.
I received an error "SetCharacterView:invalid view number(You said 0, max is 555)"
I display that anim_view is not changing the number, as it is not identifying the character from the dialog, or at least is not matching the name of the character of the dialog with the real character with exactly the same name.
Which is the same problem I already had.

Code (ags) Select
function MySay(this Character*, const string text) {
    // Starting up
    int anim_view;
   
    if (this == Sara) { anim_view = 242; }
    else if (this == Kovacs) { anim_view = 526; }
    else if (this == Mel) { if(Mel.View == 548) {anim_view = 467; }}
    Display("%d",anim_view);
    // Running speech
    this.LockView(anim_view); // lock to speaking animation
    this.Animate(this.Loop, 3, eRepeat, eNoBlock, eForwards);
    this.Say(text);

    // Ending
    this.UnlockView(); // unlock back to current view
}
Title: Re: Character.Speaking function during dialog
Post by: Crimson Wizard on Mon 13/12/2021 20:30:53
Quote from: nightmarer on Mon 13/12/2021 15:14:07
I display that anim_view is not changing the number, as it is not identifying the character from the dialog, or at least is not matching the name of the character of the dialog with the real character with exactly the same name.

How are you using MySay in dialogs? Could you post an example of your dialog script?
What happens if you Display "this.ID" or "this.Name" inside MySay?
Title: Re: Character.Speaking function during dialog
Post by: nightmarer on Mon 13/12/2021 23:04:43
I use it like:
Code (ags) Select
Sara: Bla bla bla bla.
option-on 1


this.Name is returning the right name of the character, but still is not entering in the "if" to change anim_view.
Title: Re: Character.Speaking function during dialog
Post by: Crimson Wizard on Tue 14/12/2021 00:19:26
This is strange. I might test this out myself, but in the meanwhile, would that work if you check ID instead?

i.e.
Code (ags) Select

if (this.ID == Sara.ID) { anim_view = 242; }
Title: Re: Character.Speaking function during dialog
Post by: nightmarer on Tue 14/12/2021 14:40:15
Quote from: Crimson Wizard on Tue 14/12/2021 00:19:26
This is strange. I might test this out myself, but in the meanwhile, would that work if you check ID instead?

i.e.
Code (ags) Select

if (this.ID == Sara.ID) { anim_view = 242; }

With the ID is working. :)
But without it it doesn't.