regex questions

Get help using Construct 2

Post » Sun Aug 28, 2016 4:08 pm

Hey, I'm trying to do text commands to add some power to my dialogues, however, I still have some questions about Regular Expressions.

Let's say I have this text:

Code: Select all
Hello \nI have twenty \i[1] gold coins and three \i[5] potions. \nThat's pretty cool.


Let's say this icon :) is a gold coin and this one :oops: a potion. This is how the text should render:

Hello
I have twenty :) gold coins and three :oops: potions.
That's pretty cool.


However, I have a few problems when it comes to showing icons.
I'm using this regex to detect \i[X] :
Code: Select all
"\\i\[([0-9]+)\]","g"

I want to (in thatt order):
    *Count how many "\i[X]" I have in my text (DONE)
    *For each "\i[X] get three values: The X it contains, the line it's on and it's X position compared to the text's hotspot (in order to create and correctly place the icons). For this one I have a problem as in RegexMatchAt, the Index gives me the Xth \i[X] but not the X.
    *After all Icons are created, replace all \i[X] with " " (DONE)

So, what I'd like to know is how do I extract a part of a string (aka from the beginning until my \i[X]) and extract that X when I have multiple commands in the same text.
Image
B
34
S
6
G
2
Posts: 221
Reputation: 3,324

Post » Mon Aug 29, 2016 3:59 am

I would build the string one character at a time with a loop. Upon encountering your escape character (/) have a subevent run to create the icon, skip the appropriate number of characters (the length of the /i[x] part) then continue. To position the icon correctly, you can get the len() of the string upon encountering the escape character and use that to figure out where your icon should be.

Here is an example I did for someone else for text effects, see if you can figure out how to modify it for your purposes. If you want to have the entire string shown at once, use a loop instead of every x seconds. Also the example used the text object, but you should definitely use spritefont for more control.

https://www.dropbox.com/s/211xd1ir76hq8 ... .capx?dl=0

Edit: fixed link
Last edited by oosyrag on Mon Aug 29, 2016 7:01 am, edited 1 time in total.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Aug 29, 2016 6:32 am

@oosyrag Indeed, that's an idea. I'll try it out.
However, I can't access your file, because you gave me the link to the file on your homepage. You should have clicked "Share", created a link, and then given me that link.
Image
B
34
S
6
G
2
Posts: 221
Reputation: 3,324

Post » Mon Aug 29, 2016 7:01 am

Oops, fixed.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Aug 29, 2016 7:36 am

Well, in the meantime, I used your method and it worked :D
Thanks ^^

EDIT: Omg. Your Text effects are amazing!
Do you allow me to use that in any future game I make? :o
Image
B
34
S
6
G
2
Posts: 221
Reputation: 3,324

Post » Mon Aug 29, 2016 7:43 am

Sure, no problem. Glad it worked out :)
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Aug 29, 2016 7:56 am

To what name may I credit this? Is
"Text Effects by oosyrag" enough, or do you have anything else you need credited?
Image
B
34
S
6
G
2
Posts: 221
Reputation: 3,324

Post » Mon Aug 29, 2016 7:58 am

Nah don't worry about that, it was just a quick little experiment for me, not a big deal.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Aug 29, 2016 10:38 am

Thank you :D
Image
B
34
S
6
G
2
Posts: 221
Reputation: 3,324


Return to How do I....?

Who is online

Users browsing this forum: duke2704, sebrosen and 24 guests