Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Sun 21/09/2014 11:19:36

Title: Label text character check
Post by: Slasher on Sun 21/09/2014 11:19:36
Hi,

quote from punaman:
Labels used to have a 200 character limit, but this has been removed in the latest 2.72 beta (so long as you use the Label.Text="" approach)

I'm using 3.2.1.  I'm not sure what the character limit is for labels.

Anyhow, I have a gui set up with three labels (one for each page of a case note book). Each label is only shown if it contains text, which can be added in any order (page arrows will display).

What I am aiming to do is have ags do a live count of characters in a label and when it reaches the maximum automatically put the text into the next label etc.

Help much appreciated.


Title: Re: Label text character check
Post by: Crimson Wizard on Sun 21/09/2014 12:29:02
Slasher, what Pumaman was speaking about was the memory limit of a label, not visual limit.
If I understand correctly, your problem is that you need to calculate a visual limit, so that the labels would wrap text?

You may use "GetTextWidth" function to know text visual width and compare this with label width (or gui width):
Code (ags) Select

int width = GetTextWidth(lblText1.Text, lblText1.Font);
if (width > lblText1.Width)
{
   // move some text to the next label
}

Title: Re: Label text character check
Post by: Slasher on Sun 21/09/2014 13:15:36
Hi Crimson,

I think its more about height rather than width. Like when the label has reach maximum characters it will wrap text to the next label. Bearing in mine I use Append for many lines that are added.

I will see if I can use/adjust your code.

cheers

slasher

Title: Re: Label text character check
Post by: Crimson Wizard on Sun 21/09/2014 13:30:00
Oh. So you have a wrapping line?
In which case you may use... guess what? GetTextHeight! :D


Code (ags) Select

int height = GetTextHeight(lblText1.Text, lblText1.Font, lblText1.Width + 1);
if (height > lblText1.Height)
{
   // move some text to the next label
}


Notice I use "lblText1.Width + 1" instead of just "lblText1.Width". There's a very old bug in AGS that is fixed by adding 1 to width.
Title: Re: Label text character check
Post by: Slasher on Sun 21/09/2014 16:36:00
Hi Crimson,

i put your script in rep exec:

Code (ags) Select
int height = GetTextHeight(LNotes.Text, LNotes.Font, LNotes.Width + 1);
if (height > LNotes.Height)
{
// move some text to the next label... should go from LNotes to LNotes2 label.
// when I click arrow to go to the next page the label does not display the text (click next page arrow and do labels visible properties.
 
}


I just get an error come up to shut down game.. after adding more lines than a label takes.

(roll)

cheers