Sorry for digging this up (but it's good to see the search function working again), but I have a problem with the code Scorpiorus provided me with:
function StrCutByWidth(string input, short width, char font, string output, string tail) {
/* cut string "input" into two strings "output" and "tail" where **
** "output" when displayed in font "font" has width "width" */
string text;
string temp;
StrCopy(text, input);
StrCopy(temp, "");
StrCopy(output, "");
StrCopy(tail, "");
char textLength = StrLen(text);
char i = 0;
char tail_index = 0;
while (i < textLength) {
StrFormat(temp, "%s%c", temp, StrGetCharAt(text, i));
/* if next char is space ' ' or end of string */
if ((StrGetCharAt(text, i + 1) == ' ') || (i + 1 == textLength)) {
if (GetTextWidth(temp, font) <= width) {
StrCopy(output, temp);
tail_index = i + 1;
}
else i = textLength; /* abort while loop */
}
i++;
}
if (tail_index < textLength) {
/* skip a space character unless it's the beginning of the string */
i = tail_index + (tail_index > 0);
while (i < textLength) {
StrFormat(tail, "%s%c", tail, StrGetCharAt(text, i));
i++;
}
}
}
I entered this --> "Holy crap! I can't believe it worked! This is so friggin' awesome! I can't wait to finish it now!" <-- that string and the function said that "Holy crap! I can't believe it worked! This is so friggin' awesome!" would fit in the space allotted for one line (318 pixels in this case) but when I tested the game the "awesome!" was pushed by AGS to the next line (label stretching) making it impossible to read the rest of the string " I can't wait to finish it now!" which I had stored in a label located beneath the one holding the first part of the string... Sorry if I didn't make any sense, but I'm basically just asking for someone to explain where this function went wrong...