How To Create a Large Gui That Would Hold a Lot of Text

Started by Ghostlady, Sat 09/11/2024 03:03:24

Previous topic - Next topic

Ghostlady

I would like to create a box (gui?) that will display a big chunk of text. Currently I have an image with text on it then use it as a backgroundimage in the gui. Then I swap the images to read all the images.  I don't want to put the text back on images again (for changes/corrections). It's too hard to align each to match, just not my talent. I am trying to figure out a way to drop the text into a gui without being on an image.  This will make it much easier for corrections or changes.

Background Image:

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Crimson Wizard

The most natural choice for having a text on GUI is Label control, is there any reason why you cannot use it?

Ghostlady

I did start looking at that.  Do I have to type it all in or can I copy from a word doc?
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Crimson Wizard

#3
Quote from: Ghostlady on Sat 09/11/2024 03:33:15I did start looking at that.  Do I have to type it all in or can I copy from a word doc?

You can copy/paste a text into the label's "Text" field.

If that's not convenient, or if you need to change label's text at runtime, then you may assign the label's text in script too:
Code: ags
SomeLabel.Text = "some text";

AGS script has a weird problem that it does not support breaking of a string onto multiple lines in a script file,
but there's a workaround for very long texts, is to use String.Append function like this:
Code: ags
String s = "first part of text";
s = s.Append("second part of text"); // this will concatenate previous and new text
s = s.Append("third part of text");
<...>
SomeLabel.Text = s; // this will assign full concatenated text to a label

Ghostlady

Does this mean each separate line will need the Append?
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Crimson Wizard

#5
Quote from: Ghostlady on Sat 09/11/2024 03:42:59Does this mean each separate line will need the Append?

Not line of text itself, as you see it when it's printed in game, but a line in script...

I mean a situation when you need to type a very long text, it will go too far to the right in a script editor, so you'd like to wrap it to the second line in script.
All of these lines will be glued into a seamless text using String.Append.

As for how it will look in game, labels wrap the text automatically within their width.
Additionally, you may have manual linebreaks using "\n" character combination:

Code: ags
SomeLabel.Text = "This is first line.\nThis is second line";


I suggest doing several experiments, it's easier to see and understand how it works in practice.

Ghostlady

The text is not displaying in the gui. The code below is in the OnActivate funtion.

Here's the code
Code: ags
function gGui24_OnActivate(GUIControl *control)
{
 String s = "I'll try to explain this as best I can.  Mr. Alexander and";
 s = s.Append ("I have been very close for many years.  To understand");
 s = s.Append ("our relationship I would have to give you our history.");
 s = s.Append ("Your Grand-père, Mr. Étienne and your Great Uncle,");
 s = s.Append ("Mr. Alexander were close brothers, but terrible rivals");
 s = s.Append ("since childhood.  Unfortunately, your great grand-mère");
 s = s.Append ("died giving birth to Mr. Alexander.  Now Mr. Étienne");
 s = s.Append ("being the older of the two boys, was afforded the best");

SomeLabel.Text = s; // this will assign full concatenated text to a label
}
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

eri0o

For reference if someone finds this on Google later, breaking of lines in string is supported in ags4 using the new compiler.

Now, about the problem of not showing in the Label, my guess is it's due to it's size not being large enough. Is it set to the same size of the GUI you have?

Khris

GUIs don't have an "on activate" event, just an "on click" event.
Simply assign the text to the label right before setting gGui24.Visible to true.

eri0o

Oh, right, didn't even saw that. Don't use chatgpt with AGS people, it has no idea what it does.

Ah, also if the whole GUI is still not enough, you can use a slider to vary the position of the label in the GUI to make a scroll - very old trick in ags book, works great.

Ghostlady

I got this all working good. Thanks for all the info. One question. How do I make a blank line.  Like between paragraphs?
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Snarky

You put in two line breaks. The recommended way to add a line break is "\n" (backslash is used for "escape codes" to add special characters, and "n" stands for "new line"), so "First paragraph\n\nSecond paragraph" will display as:

QuoteFirst paragraph

Second paragraph

(AGS also supports using "[" to insert a line break, but this method is no longer recommended, and I believe it is removed in upcoming versions.)

Ghostlady

Everything came out perfect.  Thanks all.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

SMF spam blocked by CleanTalk