Reading Array values with tokenat()

  • In my level editor you can place a tile on the grid and a value is written to an array in the corresponding cell. In this particular case, the value being written is

    "Tile" & "," & Tile.AnimationFrame

    To load the tiles I use the event:

    +[Array] For Each XYZ Element

    +[Compare Two Values] tokenat(Array.CurValue,1,",") = "Tile"

    -Create Tile

    -Set Tile animation frame to int(tokenat(TileArray.Curvalue,2,","))

    This loops through the array and checks if the current value's first substring equals "Tile". If so, it will create a tile in the appropriate spot and set the tile's animation frame to the second substring after being converted to an integer.

    For some reason it doesn't work. If the current value is just "Tile" then the tiles are loaded just fine, but when I write multiple values to a single cell and try to select a certain one with tokenat(), I get nothing.

    Any idea why?

  • I believe it is zero indexed, so "Tile" should have been at index 0 and Tile.AnimationFrame at 1.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Mipey is right, it's worth bearing in mind zero-based indices are the default and standard for all official features in C2 (which is different to the 1-based CC, so can be a little confusing).

    The example the manual gives is: tokenat("apples|oranges|bananas", 1, "|") returns "oranges"

  • Ah ok. I thought I tried starting with 0 but it didn't work, so I bumped it up to 1. Maybe I overlooked something! I will try it again here in a bit.

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