Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Stranga on Fri 22/03/2019 06:43:55

Title: A way to change label text to characters name when selected?[SOLVED]
Post by: Stranga on Fri 22/03/2019 06:43:55
Hey everyone,

This may be simple to someone but I haven't figured it out yet, haha! What I have is a custom dialogue system, which displays a portrait, text and the character's name. So far, I have managed to create a script to change the portrait to each character with their different emotions. Now, what I want to find i an easy way to find the character's Real Name in their properties and use that to change a label text. Right now, it only shows the player's name and not any other characters.

An Example.
Code (ags) Select


//Jason Speaking-----------------
Speaking = cJason;   
player.Faceset("Huh");//Portrait
player.Speak("U-Uh...Hey!");//Text
CloseTextBox();//Close Textbox

//Abby Speaking-----------------
Speaking = cAbigail;
player.Faceset("Huh");//Portrait
player.Speak("Can I help you, Mister?");//Text
CloseTextBox();//Close Textbox



Thanks in advance for your help! :D
Title: Re: A way to change label text to characters name when selected?
Post by: Khris on Fri 22/03/2019 15:07:33
How about

Code (ags) Select
// header
enum Faceset { eFacesetDefault, eFacesetHuh };
import void Speak(this Character*, String message, Faceset fs = 1); // Faceset is optional

// main script
void Speak(this Character*, String message, Faceset fs) {
  lblSpeak.Text = this.Name;  // answer to your actual question
  // ...
}


and

Code (ags) Select
  cJason.Speak("U-Uh...Hey!", eFacesetHuh);
  cAbigail.Speak("Can I help you, Mister?", eFacesetHuh);
Title: Re: A way to change label text to characters name when selected?
Post by: Stranga on Mon 25/03/2019 02:19:14
Thank you Khris! You've removed a ton extra work! This is fantastic! Thank you again!  :grin:

EDIT:

Also Khris, I just wanted to ask how could I assign each characters Faceset view into an enum? I was previously using a switch statement to make a database of their portraits

Code (ags) Select

/Portrait Switicher 
switch(Emotion)
   {
     case "Default": switch(Speaking)
                        {
                          case cJason:     btnPortrait.Animate(6, 0, 0, eRepeat);   break;
                          case cDad:       btnPortrait.Animate(16, 0, 0, eRepeat);  break;
                          case cMom:       btnPortrait.Animate(34, 0, 0, eRepeat);  break;
                          case cAbigail:   btnPortrait.Animate(46, 0, 0, eRepeat);  break;
                        }
     break;                   
     case "Huh":     switch(Speaking)
                        {
                          case cJason:     btnPortrait.Animate(7, 0, 0, eRepeat);   break;
                          case cDad:       btnPortrait.Animate(17, 0, 0, eRepeat);  break;
                          case cMom:       btnPortrait.Animate(35, 0, 0, eRepeat);  break;
                          case cAbigail:   btnPortrait.Animate(47, 0, 0, eRepeat);  break;
                        }
     break;
     case "Mad":     switch(Speaking)
                        {
                          case cJason:     btnPortrait.Animate(8, 0, 0, eRepeat);   break;
                          case cDad:       btnPortrait.Animate(18, 0, 0, eRepeat);  break;
                          case cMom:       btnPortrait.Animate(36, 0, 0, eRepeat);  break;
                          case cAbigail:   btnPortrait.Animate(48, 0, 0, eRepeat);  break;
                        }
     break;     


Is there an easier way to do this also?
Title: Re: A way to change label text to characters name when selected?
Post by: Khris on Mon 25/03/2019 11:26:20
You can make an array for each character and use the enum as index.

However if everything was ordered perfectly, you could calculate the loop based on this.ID and the faceset enum.

Assuming cJason is character #1 and enum values start at 1 (I can never remember whether it's 1 or 0):

Code (ags) Select
  int loop = (this.ID * 10) - 3 + faceset;

For character 1 and the first faceset enum, this sets loop to 6. And to 7 for the next enum, and so on. 16 and 17 for character #2, and so on.

(Also, independent of the ordering and the like, you can greatly shorten the existing code by setting an int and only calling .Animate() once, using the loop variable.)
Title: Re: A way to change label text to characters name when selected?
Post by: Snarky on Mon 25/03/2019 11:44:19
Quote from: Khris on Mon 25/03/2019 11:26:20
Assuming cJason is character #1 and enum values start at 1 (I can never remember whether it's 1 or 0):

Enums start from 1 by default, but you can set their values explicitly if you need to. (Any that are not explicitly set increment the value of the last one by 1.)
Title: Re: A way to change label text to characters name when selected?
Post by: Stranga on Mon 25/03/2019 14:20:55
Thanks for the help guys! I'll give this a try, just checking up arrays in the manual now. They seem simple enough to understand. Plus I got my head wrapped around enums now so I have a much better understanding of how they work now. Very handy!