How do I get value in an array cell where rows and columns have names ?

0 favourites
  • 4 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • In my game, travelling distances are important. They are stored in an array names ArrayDistances like this :

    At some points of the game, I have to retrieve the values in the table but instead of using numbers for coordinates (I know how to do that), I need to use places names (chateau, village, etc).

    So my code won't be :

    Value = ArrayDistances.At(2,3)

    but

    Value = ArrayDistances.At(cell X coordinate where value ="tour", cell Y coordinate where value="village")

    Any idea on how to do that ?

    Tagged:

  • In my game, travelling distances are important. They are stored in an array names ArrayDistances like this :

    At some points of the game, I have to retrieve the values in the table but instead of using numbers for coordinates (I know how to do that), I need to use places names (chateau, village, etc).

    So my code won't be :

    Value = ArrayDistances.At(2,3)

    but

    Value = ArrayDistances.At(cell X coordinate where value ="tour", cell Y coordinate where value="village")

    Any idea on how to do that ?

    try this

    + Array: For each XYZ element + Array: Contains "village" value -> Array: Set value in (Array.CurX, Array.CurY) to 0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would generally recommend against having labels for rows/columns within an array. There are many reasons for this, but the main one is that much easier to work with an array that contains one data type as opposed to multiple.

    I would use a second 1d array as an index, with the location/label data. It would work especially well in this case if your labels are the same on both the x and y axes.

    You can use the array.indexof() expression to get the index of any given value, but this only works on the first (x) axis of the array.

  • Thank you for your replies (and sorry for late answer)

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