Using a Second Gui and Label for a Character

Started by Ghostlady, Sun 09/06/2024 23:47:40

Previous topic - Next topic

Ghostlady

Can I use a second Gui and Label for a character.  I can't seem to get the text into the gui for this.
Example: I have a character, we'll call her Mamba.  She has a Gui16 with a label called slabel7 in the global script.

 
Code: ags
#sectionstart SaySpecial7  // DO NOT EDIT OR REMOVE THIS LINE
function SaySpecial7(Character *thechar, const string message) {
  slabel7.TextColor = thechar.SpeechColor;
  slabel7.SetText(message);
  thechar.SayAt(0, 0, 0, message); // say text but hidden (width 0), so voice speech plays
  slabel7.SetText("");
}
#sectionend SaySpecial7  // DO NOT EDIT OR REMOVE THIS LINE

She is also in the Global Header like this:
Code: ags
import function SaySpecial7(Character *thechar, const string message);

She is used in a room like this:
Code: ags
gGui16.Visible = true;
    SaySpecial7(cMamba, "The origin of 

So what I want to do is keep that Gui16 visible and let a second Gui (Gui23) open using the same character.  So I added a function in the global scrip like this:
Code: ags
#sectionstart SaySpecial23  // DO NOT EDIT OR REMOVE THIS LINE
function SaySpecial23(Character *thechar, const string message) {
  MLabel.TextColor = thechar.SpeechColor;
  MLabel.SetText(message);
  thechar.SayAt(0, 0, 0, message); // say text but hidden (width 0), so voice speech plays
  MLabel.SetText("");
}
#sectionend SaySpecia23  // DO NOT EDIT OR REMOVE THIS LINE

And did an import like this:
Code: ags
import function SaySpecial23(Character *thechar, const string message);

Then in the room did this:
Code: ags
function object0_a() {
  // script for Object 0: Interact object
 gGui23.Visible = true;
 SaySpecial23(cMamba, "This 


The Gui23 has a label called MLabel.
But the text does not appear in the Gui.  What am I doing wrong?
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

heltenjon

Quote from: Ghostlady on Sun 09/06/2024 23:47:40
Code: ags
#sectionstart SaySpecial23  // DO NOT EDIT OR REMOVE THIS LINE
function SaySpecial23(Character *thechar, const string message) {
  MLabel.TextColor = thechar.SpeechColor;
  MLabel.SetText(message);
  thechar.SayAt(0, 0, 0, message); // say text but hidden (width 0), so voice speech plays
  MLabel.SetText("");
}
#sectionend SaySpecia23  // DO NOT EDIT OR REMOVE THIS LINE
This is way above my skills, but there is a typo in line 8.

Khris

Not sure why the text doesn't appear but in theory you should check the visibility setting of the GUI and its coordinates.

However, there's no need for a secondary label, let alone a secondary GUI. (You can always just add a label to the existing GUI instead.)
Let's solve the actual problem instead: the text doesn't fit the label. It sounds like you simply need to increase the size of the label. Text too long to fit the width wraps around, but if the label isn't tall enough, it's simply not rendered on the screen. Just increase the height of the GUI and label.

(Also, you do not need the #sectionstart lines at all; these are legacy markers old 2.x versions AGS used to find functions back when it had the interaction editor.)

Ghostlady

The game is 20 years old and has been imported into the latest version of AGS so you'll see some of that Legacy stuff.  Actually, I am amazed I am able to do this. :)

Here's the code from the room.  The first thing it does is make gui 16 visible, drops some text in the gui with SaySpecial7 (character Mamba).  I have the gui16.visible=false commented out because I want that gui to stay open at the bottom of the screen.
So far so good. I can see the text and it's at the bottom of the screen.
The next thing it does, it makes gui23 visible with SaySpecial23 (character Mamba). It displays at the top of the screen. It drops some text in and all is well with that gui.
The problem is when it opens gui23 up, it removes the text from gui 16.
So I am wondering if I can't have the Mamba character in two different gui's at the same time.
I included an image that shows both guis being visible.  It shows the text that went into gui 23 and at the bottom is gui 16 with no text.


Code: ags
function object0_a() {
  // script for Object 0: Interact object
 gGui16.Visible = true;
 SaySpecial7(cMamba, "This ."); 
 //gGui16.Visible = false;

if (card0 == 0) {
  gGui10.BackgroundGraphic = 165;
  gGui10.Visible = true;
  gGui23.Visible = true;  
  SaySpecial23(cMamba, "The Fool:");    
  gGui23.Visible = false;
  gGui10.Visible = false; }
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Ghostlady

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Snarky

SaySpecial7 ends with slabel7.SetText(""); so that's why the text disappears.

Ghostlady

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Snarky

#7
Quote from: Ghostlady on Mon 10/06/2024 19:16:46I don't understand what this means.

You wrote:

Quote from: Ghostlady on Mon 10/06/2024 18:35:16The problem is when it opens gui23 up, it removes the text from gui 16.

So I am wondering if I can't have the Mamba character in two different gui's at the same time.

That is not the cause of the problem. The reason the text disappears is that the function you are calling to display it, SaySpecial7, has a command to remove it (slabel7.SetText("")) once the player clicks past the blocking SayAt call.

Ghostlady

Oh, I see.  Do you have any suggestions on how to do this?
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Ghostlady

Disregard previous post.  I am going to do something different with this. Thank you for your help!
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Khris

Just don't call your functions. Instead, show the two GUIs by making them visible and set the label texts. That's really all you need here.
If there's voice speech, run the SayAt command last, then hide the two GUIs again.

Snarky

It's hard to decide what to recommend, because I think it would be better to do the whole thing quite differently. For example, it doesn't make sense to always do:

Code: ags
  gGuiX.Visible = true;
  SaySpecial(cChar, "Blah");
  gGuiX.Visible = false;

Showing and hiding the display GUI should be part of the SaySpecial function.

However, the minimal change is to just add a line right after your call to SaySpecial7 that sets the label to the text it had.

Khris

Here's edited versions of the two functions:

Code: ags
function SaySpecial7(Character* thechar, String message) {
  slabel7.TextColor = thechar.SpeechColor;
  slabel7.SetText(message);
  gGui16.Visible = true;
  thechar.SayAt(0, 0, 0, message); // say text but hidden (width 0), so voice speech plays
  gGui16.Visible = false;
}

function SaySpecial23(Character* thechar, String message1, String message2) {
  slabel7.TextColor = thechar.SpeechColor;
  slabel7.SetText(message1);
  MLabel.TextColor = thechar.SpeechColor;
  MLabel.SetText(message2);
  gGui16.Visible = true;
  thechar.SayAt(0, 0, 0, message1); // say text but hidden (width 0), so voice speech plays
  Wait(5);
  gGui23.Visible = true;
  thechar.SayAt(0, 0, 0, message2); // say text but hidden (width 0), so voice speech plays
  gGui16.Visible = false;
  gGui23.Visible = false;
}

SMF spam blocked by CleanTalk