GML Word Wrapping not working

Discussion in 'Programming' started by Frisk17, Apr 26, 2019.

Tags:
  1. Frisk17

    Frisk17 Member

    Joined:
    Mar 19, 2019
    Posts:
    19
    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...
     
  2. Frisk17

    Frisk17 Member

    Joined:
    Mar 19, 2019
    Posts:
    19
    Oh I solved it
    I needed to check length for substr...
    Laugh out loud! I'm so dumb...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice