Creating your own Leaderboard / Highscores easy and free (PHP MySQL)


Attached Files

The following files have been attached to this tutorial:



Download now 178 KB


17,238 visits, 47,367 views


Highscores in Construct 2

Open your Construct 2 game and do the following steps:

1. Right Click and "Insert new object". Select Web -> AJAX

2. Open the highscore_example.capx to help you

3. You need a "Score" variable

4. You need a "DOMAIN_SCORES" constant. Write here your free domain! Where your phps are uploaded. Example: ""

Reading Scores

To read scores from your server database, take a look to the example .capx attached to this tutorial.

- Line 1: Here an AJAX Request reads the php file "getscores.php" from your server

- Line 3: This is what happens when the reading of the scores is completed. In this case, we will:

a) Set the group "Do Array" active: to show a Top 10 Leaderboard with names and score

b) Read the Best Score (name and score) and write them in a text field.

Scores are received as a string with the following format: name1|score1|name2|score2|name3|score3...

To access any of them you can use this:

"Best Score: " & tokenat(AJAX.LastData, 0, "|") & " - " & tokenat(AJAX.LastData, 1, "|")


"1st best score: " & tokenat(AJAX.LastData, 0, "|") & " - " & tokenat(AJAX.LastData, 1, "|")

"2nd best score: " & tokenat(AJAX.LastData, 2, "|") & " - " & tokenat(AJAX.LastData, 3, "|")

"3rd best score: " & tokenat(AJAX.LastData, 4, "|") & " - " & tokenat(AJAX.LastData, 5, "|")


Sending Scores

For sending scores, you can read the example .capx:

- Line 2: When you click "Submit", your name typed and the score (randomly generated in this example) will be sent

- Line 4: This is an example of doing some action when the score sending is succesfully completed. In this case, we will reload again the best scores.

Hope you find useful this tutorial. Let your comments in this tutorial!

Enjoy and thanks for reading!



Download now 178 KB

  • Order by
Want to leave a comment? Login or Register an account!
  • Great tutorial for a refresher. Ive just finished reading through the tutorial and will soon be implementing the PHP.

  • Have there been any updates to this - I copied it verbatim and am familiar with mYSQL and PHP a bit and this did not work for me - in terms of posting and retrieving scores? Also noticed another comment - that it wasnt saving?

  • cant save but the get score is working