This is a basic tutorial for creating a very basic highscore table.
- A webserver with PHP/MySQL support
- Basic PHP and MySQL understanding
- Basic understanding of how Construct works
The Construct part:
I made a .cap file in case my directions might be a little hard to understand so you can check out a working example.
Download it here
Create a new Direct-X project and add a variable named "Clicks" with a starting number of zero. Create an Edit Box and set the initial text to something like "Enter your name". Now create two buttons, rename them to "Click" and "Submit", change the text for "Submit" to "Submit" and go to the event sheet editor. Create a new "Always" condition and add an action for the "Click" button to set button text to "round(global('Clicks'))".
Note: "set button text to "round(global('Clicks'))"" makes the button display the number of times it has been clicked.
Note: global('<variable name>') is used for global variables.
Note: round() removes all decimals, this isn't really necessary but just to make sure that the submitted score looks like 1234 and not like 1234,00.
Create a new event for when the "Click" button is clicked and a new action that adds 1 to the "Clicks" variable. Go back to the layout editor and create a new HTTP object, then return to the event sheet editor.
Note: The HTTP object enables communication over the internet, at least one-way. I have yet to discover how to create a working both-way connection.
Create another event for when the other button is clicked and add a condition to check that "Clicks" is not zero. Then add a few actions for the HTTP object. Add two strings, one with the argument name "name" and the argument "EditBox".
Note: It is very important to not add the quotes to "Editbox" since it will use the contents of it for the variable.
The other string should have a name of "score" and an argument of "round(global('Clicks'))". The next last action to add is the post request action, set it to submit to your PHP file.
Mine is "http://localhost/scores.php?submit", you might want to change it later when we've set up the PHP file.
Lastly, add an action that resets the score when it has been submitted, that way a person can't send their score twice. You might also want to add something that indicates that the score has been submitted, but that's not necessary.
The PHP Part:
For this to work you will need a webhost who supports PHP and MySQL, I recommend WAMP if you want to set up your own.
Create a file called score.php containing:
Note: This is the file that displays the highscore, and also the file that you should link to in your game.