Hundreds of features to explore
Games made in Construct
Your questions answered
Popular & trusted by schools and Universities world-wide
Construct 3 runs in the browser & works offline
Students do not need accounts with us
Our educational partners
Free education resources to use in the classroom
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
In this tutorial you will learn how to create your own Highscores for your games, using your own free server / database. Let's go! Here's an example of how the...
Hey! Glad you liked it!
1. Some things to consider.
- Are there more than 5 scores in the Database?
- Maybe Construct2 is not deecting the Text boxes? Delete all the Text boxes and add them again.
2. In the PHP file getrank.php it adds +1. Find this line:
// Print the rank (the number of people who have better score than you + 1)
echo ($i + 1);
Then delete the +1 part.
Hope it helps fix the issues! :)
Thank you for replying! Rank was still out using the advice above but fixed it another way (I hope).
I've definitely got more than 5 scores in the database. It's updating the leaderboard order OK when I submit a new result but still nothing after row 5 (just 0 0). Have tried twice to delete and re-add text boxes (do I need to set/add anything else in the layout? It is hard to tell from your example file - there are lots of additional textScore & textNames but assume that is just for your version? Couldn't see that they were referenced anywhere within the project). Is there anything else you can think of that might be affecting it and need changing? It's so odd.
I figured it out, for some reason, the array size is set to only have 10 items in it, you need to make it bigger before you start adding things to it.
Hope this helps!
So in getscores.php I have changed it to this so I get 12 lines of results??:
// Retrieve data from database
$sql = "SELECT *
ORDER BY score
LIMIT 24"; // The 'LIMIT 24' part will only read 24 scores. Feel free to change this value
$result = mysqli_query($con, $sql);
I currently have 10 scores in my database but my leaderboard is still only showing 5 scores. Is there anything else I need to change in php files or in Construct to adjust the array size?
Thank you for looking into this for me. It has nothing to do with the initial values being 0 does it? and since 0 is a faster 'time' than other results in my database that it is showing these instead? Although the 0s are not being ordered at the top of the leaderboard so I'm guessing that isn't what's happening. The returned rank IS taking into account all the database records so I still haven't a clue.
In Construct2, find the Array object. Then make it have SCORES*2 elements. I mean, if you want 10 scores, you need an array with Size 20 (10 names + 10 scores), etc. Try this and let us know!
I'm sorry I don't know how or where to incorporate this in the construct event sheet :(
Think I've done it. I just increased the Array Width and Height Properties! Problem solved!
Thank you for your efforts to help me!
Maiko-Design That would be the way :) I had the same issue where my Height was 10 at default. Showing 20 gave me 10 results because the text array has both the name and the score so its divided by the variables needed, hence 20 = 10 scores :) Hope that helps too I know its late :P
Anytime! Glad it worked!! :)
If you need it, here is a link to my construct file: