How do I rearrange items on an string array based on some order?

0 favourites
  • 2 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • Ok, this is a tricky one.

    I store items on a string like this (it's just an example, what i actually store aren't names, but some other thing):

    Alex,14;Emanuelle,12;Hector,5;Laurence,13;Fabrizio,10

    When i want to write all these items on the screen, i use a FOR loop, and the tokenat() function to retrive all the values in order.

    It ends up like this:

    Alex 14

    Emanyelle 12

    Hector 5

    Laurence 13

    Fabrizio 10

    I want to create a function that rearranged the objects based on some property of the item. For example, rearrange the names on ascending age order, like: Hector, Fabrizio, Emanuelle, Laurence and Alex.

    How can I do that. With events.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think you need to convert these values to a 2D array, sort the array, and then convert back to string. Or just leave as the array.

    Unfortunately, Array-Sort action only sorts by first column (Y=0). Sorting other columns is a bit trickier, here is a demo I made some time ago:

    dropbox.com/s/88wse8qyrr3ysgs/arraySort.capx

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