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.
//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
How about
// 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
cJason.Speak("U-Uh...Hey!", eFacesetHuh);
cAbigail.Speak("Can I help you, Mister?", eFacesetHuh);
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
/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?
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):
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.)
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.)
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!