Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ghostlady on Sat 09/11/2024 03:03:24

Title: How To Create a Large Gui That Would Hold a Lot of Text
Post by: Ghostlady on Sat 09/11/2024 03:03:24
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:

(https://mysterymanor.net//junk/TextBoxSample.JPG)
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: Crimson Wizard on Sat 09/11/2024 03:31:17
The most natural choice for having a text on GUI is Label control, is there any reason why you cannot use it?
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: Ghostlady on Sat 09/11/2024 03:33:15
I did start looking at that.  Do I have to type it all in or can I copy from a word doc?
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: Crimson Wizard on Sat 09/11/2024 03:38:28
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) Select
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) Select
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
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: Ghostlady on Sat 09/11/2024 03:42:59
Does this mean each separate line will need the Append?
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: Crimson Wizard on Sat 09/11/2024 03:48:14
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) Select
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.
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: Ghostlady on Sat 09/11/2024 04:37:08
The text is not displaying in the gui. The code below is in the OnActivate funtion.

Here's the code 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
}
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: eri0o on Sat 09/11/2024 09:22:01
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?
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: Khris on Sat 09/11/2024 10:40:22
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.
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: eri0o on Sat 09/11/2024 12:05:48
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.
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: Ghostlady on Sun 10/11/2024 06:45:42
I got this all working good. Thanks for all the info. One question. How do I make a blank line.  Like between paragraphs?
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: Snarky on Sun 10/11/2024 08:15:06
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.)
Title: Re: How To Create a Large Gui That Would Hold a Lot of Text
Post by: Ghostlady on Tue 12/11/2024 03:09:57
Everything came out perfect.  Thanks all.