How do I sort an array?

0 favourites
  • 3 posts
From the Asset Store
A master sorting Puzzle fun and addictive puzzle game! A challenging yet relaxing game to exercise your brain!
  • so i have data on x axis that stores hero type, level, star, awakening.

    and the y axis holds the different heroes

    0,0 is type 1 1,0 level 100. 2,0 5star

    0,1 is type 2 1,1 level 50 etc

    i want to sort them so level 100 is first on the list

    i saw the sort function, and the reverse function to do this

    but. this is only sorting a y axis.. like all the levels. so 100 first 99 second. the type/star/awakening all remain in the same order on their own y axis.

    so if i have a

    1,10,5,0

    2,100,10,3

    then i end up with

    1,100,5,0

    2,10,10,3

    i need it to sort all colomns based of the y "level" not just sort the levels leaving the other values in the same place.

    thanks. hope i explained it well. ill continue to look online for previous examples

  • This is how I use arrays for data like that.

    Here is some example data: 0, name, x, y

    The 0’s will be changed in events so we can sort by any property we want. See the end of the post.

    0, “orc”, 15, 34
    0, “fish”, 100,100
    0, “axe”, 5, 55

    Which is an array of size (3,4,1). Indexes of the values are:

    (0,0), (0,1), (0,2), (0,3)
    (1,0), (1,1), (1,2), (1,3)
    (2,0), (2,1), (2,2), (2,3)

    So you access values with array.at(item, property)

    Item is 0 for the first, 1 for the second and so on.

    Property is

    0 - sort value

    1 - name

    2 - x

    3 - y

    Now to sort the list you’d first copy any property you want to sort by to the first value in the line and sort by x.

    On function sort(property)
    — Array: for each x
    — — array: set (array.curX, 0) to array.at(array.curx, property)
    — [blank event]
    — — array: sort by x
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i got it to work. i load the json into an array

    then, i filter search for values like you suggested. and just add them into a new array with all x data

    though i would post it, in case anyone else wants a visual example

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