Sorting a table. Can it be done?

helpingtogrowhelpingtogrow Member, PRO Posts: 74

Can a table be displayed in the editor mode sorted?

Comments

  • bob loblawbob loblaw Member, PRO Posts: 793

    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 Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    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 Member, PRO Posts: 5,332

    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 Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited September 2018

    @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 Member, PRO Posts: 5,332

    @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 Member, PRO Posts: 793

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

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

    @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 Member, PRO Posts: 793

    @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.