How do I sort text array values?

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
  • Hey guys,

    I'm trying to learn how to sort my array values that contains a specific text

    I just want to be able to pick a text, and move them to the top of my list.

    I don't want ascending/descending orders of numbers, I just want to isolate a category if that makes sense!

    Example:

    1,5,Grape

    10,4,Grape

    3,6,Grape

    5,7,Apple

    3,5,Pineapple

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I could be wrong - but I'm pretty sure the in-built sort feature includes alphabetical as well as numerical searching. You'd have to move the text over to be the first index on the X axis, but then the in-built sort function should work fine.

    EDIT: Sorry - just re-read your post. To move a group to the top of the list, simple iterate through the array checking for the identifier you're looking for. When you find that identifier, push a new value to the front of the array containing the values from that index - then delete the original index.

    If you want everything grouped beforehand, you'll need a place to store a list of all of the text values stored in the third column, then perform the above process for each item on that list.

  • If you set the text as the first index then you could just use the sort action.

    As is the first value is a number so it would be sorted like this:

    1,5,Grape

    3,6,Grape

    3,5,Pineapple

    5,7,Apple

    10,4,Grape

    but if you set the array up like this:

    grape,1,5

    grape,10,4

    grape,3,6

    apple,5,7

    pineapple,3,5

    then sort would do make it like this:

    apple,5,7

    grape,1,5

    grape,10,4

    grape,3,6

    pineapple,3,5

    Besides that you could implement your own sorting. "bubble sort" is probably the simplest to do just look at wikipedia for some psuedo code. But it's probably easier to just rearrange your data and use the sorting action.

  • I ended up going with R0J0hound's method, thank you so much! that worked for me =)

    yeah, its weird...i cant seem to sort from the 3rd value =/ does it only work on the first?

  • Yeah, only the first value is used for sorting.

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