Friday, November 20, 2015

Construct2 example: Local Leaderboard using array

Friend of mine sent me a question how to create a local leaderboard for Top10 scores/times/results/whatever in Construct 2.

I want to introduce one simple way to implement leaderboard locally (no server required). Solution can be seen in this screenshot:


Brief description of the method used:

  1. Save new score to variable for further use (in this case inputScore)
  2. Check if new score is greater than the lowest value in current array
    => If it is greater, replace lowest value with new score (inputScore)
  3. Sort array contents to descending order using this simple algorithm:
    => Take two consecutive elements from the array, starting from bottom, and compare them
    => If two consecutive elements are not in correct order, swap them

Basically, this is very simple to do if you understand how to access arrays in C2.

You can try HTML5 version to get an idea how this works. Example is using textbox for collecting score values, and it should work on mobile devices too.

Also, if interested about the "source code, there is a Construct2 .capx available for download.

Have fun!

-Jussi.

No comments:

Post a Comment