How do I do a text parser (or something)?

0 favourites
  • 12 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • Hello.

    I'm creating a dialogue system rpg-style, and I would like to display the words letter-by-letter until the end of the text is reached rather than just show all the text at once. But I have no idea how to set this kind of thing up. Has anyone here done this before? Are there any examples around that I can look at? I'm using C2's Sprite Font for text btw.

  • Do a search for 'typewriter' - there are several examples.

    I think that might be what you're after (hopefully).

  • Thanks, will do

  • Here's an example that uses a normal text field, but using spritefont should be just as easy.

  • Here's an edited version with some added magic to remove the "partial word not wrapping" problem.

  • Thanks a lot fellas! Haha I was just wondering how to handle the wrapping thing. Good stuff

  • Magistross

    I tried and failed to adapt your functions to work with SpriteFont Like the image below shows, I decided to try and bypass the textWidth function since it returns width based on the Arial font (right?). I made a local variable instead to hold the pixel width of the font minus character spacing and multiplied by the loopindex. But I'm missing something obviously because text doesn't display at all right now.

  • I once did the same thing for SpriteFont, you only have to adapt the "textWidth" function so it returns the width based on the characters in the sprite instead of using that javascript function (which indeed use 12pt Arial for its calculation; the font used by the DestText object).

    2 ways to do that, depending on your need.

    If your spritefont is monospaced, it's much easier. The "textWidth" function should return len(Function.Param(0)) * (characterWidth + characterSpacing).

    However, if some characters have different width, you'll have to use the SpriteFont.TextWidth expression. You can either use a dedicated SpriteFont to "measure" text, or create a temporary one to do it.

    Here's an edited version using a SpriteFont.

  • It works great! Nice job and thanks so much for sharing =D You the man!

  • Magistross Thanks! I don't understand what the "RegexMatchCount" expression does though, and why you're putting ""[^\s]+|[\s]+", "g"" at the end.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It gives me the match count so I know how many groups of characters there are. A group is either all non-whitespace [^\s] (I should have used \S but it'll work anyway), or all whitespaces \s. Iterating through those, each one is appended to a temporary spritefont until the width becomes too high. When that occurs, a newline is inserted and the process continues. In the end, you obtain a text with newlines placed to make it fit in a predetermined width.

  • Hi, I try to implement this technique by calling a function whenever a character needs to inform the player about smth. Function has 2 params: text itself, text object ID.

    inside a function I set a variable, and while it is set I do the "every 0.05 sec" routine with function parameter 1 instead of SourceText.Text (as in example)

    No typing is detected sofar and the only text I've received is "text"

    Can anyone help me?

    p.s. I use rex's function2, but it shouldn't be a problem, right?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)