How do I sort a leaderboard using an array?

0 favourites
  • 7 posts
From the Asset Store
Easy Leaderboard is a simple 3-column (position, name, score) leaderboard with a customizable appearance
  • Hey everyone,

    I'm working on a leaderboard in Construct 3 where I store team names and their scores in an array. I’ve already managed to correctly insert the data into the array and display it in a list, but now I’m trying to sort the leaderboard so the team with the highest score appears at the top.

    I’m using a comparison-based sorting algorithm to swap the values in the array, but I’m running into some issues. I’ve set up a loop to compare the values and swap them, but I can’t seem to get it to work properly. Here are the issues I’m facing:

    The leaderboard isn’t being sorted correctly. Some values are duplicated, and the team with the highest score isn’t appearing at the top.

    I’m using a nested loop to compare and swap the values, but I can’t get it to work without duplicating or showing the wrong results.

    I’ve attached an image of my current code. If anyone has any advice on how I can improve this sorting process or what I might be doing wrong, I’d really appreciate it!

    My code:

    What I got:

  • It is more logical to put the team points in the first cell and sort by the built-in sort command.

  • Thank you for your suggestion! However, in most sports leaderboards, it's uncommon to see the points listed before the team names.

    I understand that sorting by points as the first column might simplify things technically, but I’m trying to maintain the traditional layout where team names appear first. If you have any ideas on how to achieve that, I’d greatly appreciate it!

    Thanks again for your input! 😊

  • Thank you for your suggestion! However, in most sports leaderboards, it's uncommon to see the points listed before the team names.

    I understand that sorting by points as the first column might simplify things technically, but I’m trying to maintain the traditional layout where team names appear first. If you have any ideas on how to achieve that, I’d greatly appreciate it!

    Thanks again for your input! 😊

    How the data is stored in the array is not hardwired to how you output it.

    You can of course continue to use your order and sort it manually, for example by bubble.

    But it is more logical to sort by the built-in method and when outputting the results just output the first team name from cell 1 and the result from cell 0.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have populated an array with the team names and scores, and I am using events to sort the array from highest to lowest score, switching to the second column. However, I'm facing two issues:

    - "Team1" does not appear: Despite setting the team names and scores correctly in the array, Team1 is not showing up in the final output. Instead, I see "Team2" and "Team3" with their correct scores, but "Team1" is missing (I got "NaN").

    - Text Appears in Bold: The text displayed for the leaderboard seems to be in bold, even though it shouldn't be. I haven't set any special formatting for the text, so I'm not sure why this is happening.

    Here's a snippet of my events:

  • -The text is bold because you have 60 text objects being created every second and overlaid on top of each other. You can see it in the debugger.

    -You can also see what is in the array after sorting in the debugger.

    -Action 2 is executed 60 times per second and so is action 4.

  • I think I should have made and posted my own version right away, rather than writing all these posts.

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