regex questions

0 favourites
  • 9 posts
From the Asset Store
Logo Quiz with 150 prepared logos and answers, automatic question and answer mixing
  • 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:

    Hello \nI have twenty \i[1] gold coins and three \i[5] potions. \nThat's pretty cool.[/code:1v5oohwz]
    
    Let's say this icon    a potion. This is how the text should render:
    
    [quote:1v5oohwz]Hello
    I have twenty  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:1v5oohwz]"\\i[([0-9]+)\]","g"[/code:1v5oohwz]
    I want to (in thatt order):
    [ul]
    *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)
    [/ul]
    
    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.
  • 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

  • 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.

  • Oops, fixed.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well, in the meantime, I used your method and it worked

    Thanks ^^

    EDIT: Omg. Your Text effects are amazing!

    Do you allow me to use that in any future game I make?

  • Sure, no problem. Glad it worked out

  • To what name may I credit this? Is

    "Text Effects by oosyrag" enough, or do you have anything else you need credited?

  • Nah don't worry about that, it was just a quick little experiment for me, not a big deal.

  • Thank you

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