GML Word Wrapping not working

Frisk17

Member
I'm trying to do word wrapping by replacing " " character with "\n"

I take the max length(OF CHARACTERS) and of the string then apply one every time limit crosses...

Code:
///@desc string_wrap
///@arg string
///@arg max_width

//SOME VARIABLES
var str = argument[0];
var max_length = argument[1];

var str_length = string_length(str);
var last_space = 1;

var count = 1;
var substr;

//Incrementing to check
repeat(str_length)
{
    //String of the count
    substr = string_copy(str, 1, count);
   
    //Set the last space
    if(string_char_at(str, count) == " ") last_space = count;
   
    //Is length crossed??
    if(str_length > max_length)
    {
        //Delete the extra space
        str = string_delete(str, last_space, 1);
        //Insert a newline
        str = string_insert("\n", str, last_space);
        count++;
    }
   
    count++;
}

//Return to the value
return str;
My text is "LOL! Hahahahhaahah I'm the TEXT!!! YAYAYAYAYYAYAYAYAYAYAYAYAY!"

Now what I'm getting is that "OL
Hahahahhaahah
I'm
....
YAYAYAYAYYAYAYAYAYAYAYAYAY!"
I get the L deleted and newline every space..

I tried debug messages and their values are correct.

Uh.... any solutions?

Please help...
 
Top