organizing a table based on the highest score?

scottharrrules43scottharrrules43 Tulsa, OklahomaMember, PRO Posts: 694

Let's say you have a a bunch of scores in a table? How do find out which is the highest score, what is the second high score and so on?

Comments

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    Use the (max) function and plug all of your table cells in there.

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    You would then, based off of that max attribute, write the numbers back to the table.

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

    I'm working on a bubble sort to do just this but it's proving difficult. Recursion in GameSalad is not really achievable without spawning a new actor to act as a recursive call.

    @Braydon_SFX‌ Do you have an algorithm for sorting several numbers using the max() function? I could see doing max(tableCell1,tableCell2,tableCell3) but then you'd have to repeat it without the highest number and keep going until none were left.

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

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @tatiang‌ -- Yeah that's where it can get difficult. The easiest way I can think of right now (and mind you, this is late in the evening) is to put all of that in a loop so that it grabs the highest value, writes it to a new table, and then you'd have to change that value you grabbed from the regular score table to a low number so it's not picked again.

    I haven't actually tried it -- but I think that may work (possibly with some tweaking of the above). It's not elegant, but right now I cant/dont want to think up an algorithm to do that. ;)

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @tatiang‌ -- Here's an example that's working.
    Note: I originally had the Change Table Value (in the round rules actor) to change the value I just grabbed to 0, so it wouldn't pick that number again as the highest. However, the game wasn't actually changing it to 0. It's like it couldn't pick the row that I wanted to write to. So I used the tableSearchValue to have the game go and get the row, then I wrote to that row with a hooked in attribute.

    Phew, could be me on a late night, but that took longer than it should have. ;)

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

    @Braydon_SFX‌ Okay, that idea makes a lot of sense. I'll take a look at your demo. I think my recursive method is close to being done so I'll post that if it ends up working well.

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

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

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

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @tatiang‌ -- Very nice! Good logic in there.

  • scottharrrules43scottharrrules43 Tulsa, OklahomaMember, PRO Posts: 694

    thank you, @Braydon_SFX‌

  • scottharrrules43scottharrrules43 Tulsa, OklahomaMember, PRO Posts: 694

    just a quick question @Braydon_SFX‌ , is there a way to make it work even if you add an another row and get it to work? So if another row is add in the middle of a game it will sill pick form the column?

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @scottharrrules43‌ -- Yes , but you'll need to have the rows plugged into the max() function (located in the round rules). Right now I believe I have three tableCellValues plugged in, but if you need more feel free to add more.

    If you want to add a row in the middle of the game? Hmm, that's more difficult. You'd have to have a Loop inside a rule that says something like this:
    Rule: When tableRowCount = 2,
    Loop. Inside the loop is the max function. Make sure that only 2 tableCellFunctions are plugged in.

    Rule: When tableRowCount = 3,
    Loop. Inside the loop is the max function. Make sure that only 3 tableCellFunctions are plugged in.

    Rule: When tableRowCount = 4,
    Loop. Inside the loop is the max function. Make sure that only 2 tableCellFunctions are plugged in.

    And so on. It's tedious. Haven't taken a good look at @tatiang‌'s demo yet, but his might be better for what you're looking for if it works based off a the tableRowCount function.

  • scottharrrules43scottharrrules43 Tulsa, OklahomaMember, PRO Posts: 694

    Ok thank you

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

    Yes, my demo works for any number of columns. I built it using columns because I keep track of a specific quiz number with a row attribute but it could be adapted to use rows instead.

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

Sign In or Register to comment.