parsing a text string to an array?

0 favourites
  • 5 posts
From the Asset Store
OpenAI TTS
$10 USD
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • I've been.racking my brain trying to figure this out for a week so I thought I'd post here and finally give up and ask for help lol, here's what I'm trying to

    I want to be able to take a string of text, example: "wwwbbbss" and parse it into an array where each one character in the string parsed to a seperate array value,(w in 1,0 thru 3,0 b in 4,0 etc.)

    Basically I'm trying to make a level editor that I can make txt levels with at work on my phone lol then email em to myself and play on construct lol

    Any help would be greatly appreciated

    Thanks!

  • I'm actually doing something very similar to that, too!

    You're probably looking for the "tokenat()" expression.

    tokenat(src, index, separator)

    Return the Nth token from src, splitting the string by separator. For example, tokenat("apples|oranges|bananas", 1, "|") returns oranges.edited><editID>Zero6</editID><editDate>2012-08-24 07:39:03</editDate></edited>

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • from the example i made i'd need to have my string set to something like, "w|w|w|b|b|b|s|s"?

    and then, to retrieve an item i'd enter something like

    tokenat("w|w|w|b|b|s|s",6,"|")

    would return the first S?

  • the count starts with 0, so it would be the second "s"

    EDIT: If you like to work without separators, you can use the "left" and "right" expressions.

    Based on your example:

    wwwbbbss

    to get the 4th entry, use this code:

    right(left("wwwbbbss",4),1)

    this would return the first "b"

    EDIT2: mid can be used too:

    Same example as above but the expression would be:

    mid("wwwbbbss", 4, 1)

  • tokenat is the way to go if you ever need more than a single letter/digit to represent somethin

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