To print text by one letter

Discussion in 'Programming' started by seojaeoh, Mar 17, 2019.

  1. seojaeoh

    seojaeoh Member

    Jan 22, 2019
    I learned how to print text a while ago. But I wanted to know how to print text one by one, so I watched the video, and I didn't understand. If you know how to print text one by one, could you tell me? I can only think of how to print one character after another.
  2. marasovec

    marasovec Member

    Sep 15, 2016
    Typewriter effects are really simple. You have one string you want to write and a second string you are printing. You need a counter that copies letters from the first string every x steps and adds the letter to the second string you are printing.
    Here is a nice tutorial:

    It also works for GMS2
  3. dannyjenn

    dannyjenn Member

    Jul 29, 2017
    Off the top of my head, the easiest way to do this is as follows:
    text = "The quick brown fox jumps over the lazy dog.";
    new_text = "";
    i = 1;
    alarm[0] = 4;
    // alarm[0] event:
        new_text += string_charat(text,i);
        i += 1;
        alarm[0] = 4;
    // draw event:
    The important part is the alarm[0] event. Basically, i is the letter we're currently on (e.g. when i is 1, then the letter is "T". When i is 2, the letter is "h", etc.) So we first check that i is less than to the length of the text. (This check might not be necessary... I'm not sure.) If it is, we want to concatenate the next letter onto the new string, and we also want to increment i (in order to move onto the next letter the next time the alarm goes off), and reset the alarm. So the first the the alarm goes off, we end up with "" + "T", which is "T". On the second time, we end up with "T" + "h", which is "Th". On the third time, we end up with "Th" + "e", which is "The". And so on.

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