GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sorting a table. Can it be done?

helpingtogrowhelpingtogrow Posts: 27Member, PRO

Can a table be displayed in the editor mode sorted?

Comments

  • bob loblawbob loblaw Posts: 96Member, PRO

    not sure if there’s a function to do it but using two if a > b functions, one within the other, looping by the number of values within the original would do it (if i’m remembering what i did in college a long time ago). you’d also need a temp table to write values to while it sorts.

  • tatiangtatiang Posts: 11,414Member, Sous Chef, PRO, Senior Sous-Chef

    Funny you should ask, I was just working on a table sort method today. It was slow so I wasn't too happy with it.

    If you want to sort while editing a table, the best way to do that is to sort it in Excel/Google Sheets and then import the sorted table. Yes, I wish you could do it in GameSalad but you can't.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Posts: 4,621Member, PRO

    I made a few bubble sorts which work fine for smaller tables. I spent an few hours last night working on trying to speed it up, for bigger tables (1000+ rows) and I too found it hard to reach worthwhile speeds. I'll update if I come up with something quick enough. There are table sorts built into Lua, shame none of them made it into GS.

  • tatiangtatiang Posts: 11,414Member, Sous Chef, PRO, Senior Sous-Chef
    edited September 14

    @Armelline said:
    I made a few bubble sorts which work fine for smaller tables. I spent an few hours last night working on trying to speed it up, for bigger tables (1000+ rows) and I too found it hard to reach worthwhile speeds. I'll update if I come up with something quick enough. There are table sorts built into Lua, shame none of them made it into GS.

    Yeah, I started with a Bubble Sort, too, and found it slow for large tables. With my limited knowledge of sort methods -- I then tried a Shell Sort -- and GameSalad's lack of true recursiveness (except perhaps for self-spawning an actor), I couldn't get very far. Kinda wish the developers would just figure out a way to add a tableSort behavior since they are worlds more talented at this than I am.
     
     
    RIP Graphene.
     

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Posts: 4,621Member, PRO

    @tatiang said:
    Yeah, I started with a Bubble Sort, too, and found it slow for large tables. With my limited knowledge of sort methods -- I then tried a Shell Sort -- and GameSalad's lack of true recursiveness (except perhaps for self-spawning an actor), I couldn't get very far. Kinda wish the developers would just figure out a way to add a tableSort behavior since they are worlds more talented at this than I am.

    I went the exact same path with the exact same results. It's a shame we can't even find the cell with the highest value in it, as that would open up all kinds of new sorting options.

    Definitely something that would be best solved with a new table function. @adent42 something to think about perhaps when you've finished/need a break from all the Android madness! tableSort(table,column,options)

  • bob loblawbob loblaw Posts: 96Member, PRO

    if you could use a loop behaviour within another loop behaviour it would be easy, and done before you blink.

  • tatiangtatiang Posts: 11,414Member, Sous Chef, PRO, Senior Sous-Chef

    @bob loblaw said:
    if you could use a loop behaviour within another loop behaviour it would be easy, and done before you blink.

    Yep. But that never seems to work. :(

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • bob loblawbob loblaw Posts: 96Member, PRO

    @tatiang said:

    @bob loblaw said:
    if you could use a loop behaviour within another loop behaviour it would be easy, and done before you blink.

    Yep. But that never seems to work. :(

    i was trying to get it to work for about half an hour or so to leave a demo, but could only get the first step of the sort going, before i realised it said loop was one of the behaviours that couldn’t be used in a loop in the loop description.

    bummer.

Sign In or Register to comment.