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

Get help using Construct 2

Post » Wed Aug 13, 2014 7:16 pm

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.
B
39
S
16
G
6
Posts: 543
Reputation: 7,619

Post » Wed Aug 13, 2014 7:28 pm

Do a search for 'typewriter' - there are several examples.
I think that might be what you're after (hopefully).
If your vision so exceeds your ability, then look to something closer.
Moderator
B
136
S
31
G
87
Posts: 5,496
Reputation: 60,278

Post » Wed Aug 13, 2014 7:34 pm

Thanks, will do :)
B
39
S
16
G
6
Posts: 543
Reputation: 7,619

Post » Wed Aug 13, 2014 8:05 pm

Here's an example that uses a normal text field, but using spritefont should be just as easy.
You do not have the required permissions to view the files attached to this post.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
136
S
31
G
87
Posts: 5,496
Reputation: 60,278

Post » Wed Aug 13, 2014 9:13 pm

Here's an edited version with some added magic to remove the "partial word not wrapping" problem.
You do not have the required permissions to view the files attached to this post.
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735

Post » Wed Aug 13, 2014 10:59 pm

Thanks a lot fellas! Haha I was just wondering how to handle the wrapping thing. Good stuff :)
B
39
S
16
G
6
Posts: 543
Reputation: 7,619

Post » Thu Aug 14, 2014 9:23 am

@Magistross
I tried and failed to adapt your functions to work with SpriteFont :P 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.

Image
B
39
S
16
G
6
Posts: 543
Reputation: 7,619

Post » Thu Aug 14, 2014 2:15 pm

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.
You do not have the required permissions to view the files attached to this post.
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735

Post » Thu Aug 14, 2014 10:54 pm

It works great! Nice job and thanks so much for sharing =D You the man!
B
39
S
16
G
6
Posts: 543
Reputation: 7,619

Post » Mon Feb 09, 2015 12:46 pm

@Magistross Thanks! I don't understand what the "RegexMatchCount" expression does though, and why you're putting ""[^\s]+|[\s]+", "g"" at the end.
B
151
S
75
G
20
Posts: 1,793
Reputation: 22,749

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 12 guests