Reading Array values with tokenat()

Get help using Construct 2

Post » Thu Jun 14, 2012 4:10 am

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? Tokinsom2012-06-14 04:19:09
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Thu Jun 14, 2012 9:33 am

I believe it is zero indexed, so "Tile" should have been at index 0 and Tile.AnimationFrame at 1.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,180

Post » Thu Jun 14, 2012 2:03 pm

@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"Ashley2012-06-14 14:04:01
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,694

Post » Thu Jun 14, 2012 2:54 pm

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.
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 16 guests