Jibble

Author Topic: SetLabelText exception - Error: text too long  (Read 1463 times)

fovmester

  • I am slowly making progress...
    • I can help with translating
    • fovmester worked on one or more games that was nominated for an AGS Award!
SetLabelText exception - Error: text too long
« on: 18 Mar 2006, 09:08 »
I'm using a gui to be a book in my game, where the text of the pages are a label. When turning the page I simply exchange the label text with another text from a big array. But when I run the game and turn the page I get this exception:

Error: SetLabelText: text too long

The text I tried to insert into the label was 192 characters long. It covers about half the page, which is also about half the size of the label.

I tried typing the same text into the label from the editor and it showed up fine in the editor, covering about half the page as expected.

Now, why then do I get this error when I use Label.SetText? I guess Label uses an array of characters (or maybe std::string?) to save the characters, and so it shouldn't be a limit put by storage space. I guess the limit is something that CJ has decided then, and if it's not too difficult, then please CJ, remove this limitation, because as far as I see it makes no sense and it would make my book work without having to do a lot of ugly workarounds.

RickJ

  • fix'n one thing and break'n two ...
    • I can help with scripting
    • I can help with story design
    • RickJ worked on one or more games that was nominated for an AGS Award!
Re: SetLabelText exception - Error: text too long
« Reply #1 on: 18 Mar 2006, 09:21 »
Are you using the latest AGS beta?   Are you using the new method of setting the text?   

// The new way
Label.Text = ".......";

or

// The old way
SetLabelText("....");

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
Re: SetLabelText exception - Error: text too long
« Reply #2 on: 18 Mar 2006, 14:40 »
Actually it goes like this:

// AGS 2.71 and later
Label.Text = "text";

// AGS 2.7
Label.SetText("text");

// AGS 2.62 and prior
SetLabelText("text");

You suggested that new-style Strings require the latest beta and forgot completely about the 2.7 method.

In any case, for AGS 2.7 and prior (which use old-style strings), there is a 200 character limit (this is because "string" is defined internally to be a char array of 200 characters).

I'm not sure why using 192 characters would crash, but perhaps you could try downloading the latest version (AGS 2.71) and using new-style Strings (note the capital 'S').  The limit for Strings is 2048 characters (I believe), so there shouldn't be any problems there.

Although...are you absolutely sure the text was 192 characters long?  It just doesn't seem like it should crash for anything less than 200 characters.  Perhaps you could post the exact line of code that is crashing the game?

[EDIT:]

Ohh...It seems that before AGS 2.72 BETA 3 Labels still had their text truncated to 200 characters (even if you use a String).  But still...200 != 192.
« Last Edit: 18 Mar 2006, 14:45 by monkey_05_06 »

fovmester

  • I am slowly making progress...
    • I can help with translating
    • fovmester worked on one or more games that was nominated for an AGS Award!
Re: SetLabelText exception - Error: text too long
« Reply #3 on: 19 Mar 2006, 10:01 »
I use v 2.71 of AGS and first I had used Label.SetText but now I switched to Label.Text = ...

It's the same result. And I double-checked the nbr of characters and according to the word count in MS Word it's 195 character. So it is still < 200. Here's the text anyways:

Known by it's large leaves, the thief salvae is a brownish plant. The name comes from its dousing abilities commonly used by thieves. It grows in dark places, often inside caves or under bridges.

Here's the whole Book-code which handles everything concerning the books. I also added a check to see if it was really the text above and nothing else that was put in the label. And it was. I don't understand why I get an error! Shouldn't it truncate the text like you said, monkey?

Code: [Select]
// Main script for module 'Book'


#define BOOKSIZE 10
#define MAX_NBR_OF_BOOKS 10

struct BookContent {
  String title[BOOKSIZE];
String text[BOOKSIZE];
int nbrOfPages;
bool read;
};

BookContent books [MAX_NBR_OF_BOOKS];
int currentBook;
int currentPage = 0;

static function Book::addPage(int bookNbr, String title, String text) {
    int pageNbr = books[bookNbr].nbrOfPages;
    books[bookNbr].title[pageNbr] = title;
books[bookNbr].text[pageNbr] = text;
books[bookNbr].read = false; // cannot have read whole book anymore
books[bookNbr].nbrOfPages++;
}

// Shows the BOOK gui and handles reading through the book
static function Book::readBook(int bookNbr) {
  gBook.Centre();
  currentBook = bookNbr;
  books[bookNbr].read = true;
 
  gcLTitle.SetText(books[bookNbr].title[0]);
  gcRTitle.SetText(books[bookNbr].title[1]);
  gcLPage.SetText(books[bookNbr].text[0]);
  gcRPage.SetText(books[bookNbr].text[1]);
  gcLNbr.SetText("1");
gcRNbr.SetText("2");
  gBook.Visible = true;
}

static function Book::getCurrentBook() {
  return currentBook;
}

static function Book::getNbrOfPages(int bookNbr) {
return books[bookNbr].nbrOfPages;
}


// Called when clicking on the turn page buttons or the close book button.
static function Book::interface_click(int interface, int button) {
if (interface == BOOK) {
int bNbr = currentBook;
String p1;
String p2;
String t1;
String t2;

if (button == 2 && currentPage > 0) //turning to a lower page
currentPage-=2;
if (button == 3 && currentPage < Book.getNbrOfPages(bNbr)-2) //turning to a higher page
  currentPage+=2;
 
if (button == 2 || button == 3) {//turning the page

   
   t1 = books[bNbr].title[currentPage];
   p1 = books[bNbr].text[currentPage];
   t2 = books[bNbr].title[currentPage+1];
   p2 = books[bNbr].text[currentPage+1];
   
   //checking if the text in p1 really is what I think it is.
Overlay* i = Overlay.CreateTextual(0, 30, 300, 0, 65472, p1);
WaitMouseKey(4000);
i.Remove();

     gcLPage.Text = p1; //HERE COMES THE EXCEPTION
     gcRPage.Text = p2;
     gcLTitle.Text = t1;
     gcRTitle.Text = t2;
     
  } else if (button == 4) { //quit button
    currentPage = 0; //resets page
    gBook.Visible = false;
  }

gcLNbr.SetText(String.Format("%d",currentPage+1));
gcRNbr.SetText(String.Format("%d",currentPage+2));
}

}

Pumaman

  • Creator of AGS
  • Administrator
  • Mittens King
  • I sense danger.
    • Lifetime Achievement Award Winner
    • Pumaman worked on one or more games that won an AGS Award!
    •  
    • Pumaman worked on one or more games that was nominated for an AGS Award!
Re: SetLabelText exception - Error: text too long
« Reply #4 on: 19 Mar 2006, 18:26 »
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)


monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
Re: SetLabelText exception - Error: text too long
« Reply #5 on: 19 Mar 2006, 22:00 »
But yet the string of text is only 195 characters.