Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Tutorial: Online High Score Board

Author
Message
Hockeykid
DBPro Tool Maker
16
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 24th May 2010 11:18 Edited at: 16th Nov 2011 02:09
Hello everyone, this is an "indepth" tutorial on how to setup an online high score board system. I mainly did this because around 2 weeks ago I searched everywhere to try and figure it out and noticed that no one ever made a tutorial (to my knowledge). By the way please try to excuse any grammar mistakes in this tutorial as I started it at 2 am and finished it at 4 am so my eyes are a bit heavy at the moment.
Enjoy

Credits go to Plystire for staying up all night helping me figure it out and doing most of the work. O and for just for being awesome .

1. Hosting a database
Start of by going to http://freehostingphpmysql.com/

Sign up for a free account (on the bar at the top hit the "Signup" and choose the "Free hosting plan".)

Once signed up and logged into your account click the "Website Manager" tab on the top bar.



Off to the left hand side you will see a panel. Click the "MySQL" option.



Proceed by creating a new database (the Username and Password do not matter as long as you remember them)



Once created open the database page by clicking the blue hyper link of your database just below the database creation area.



A new page will open asking you to log in. Log in using your newly created databased
username and password.


Once you log in off to the left you will see your database name. Click on it and you will be brought to a new page to create tables. For this purpose (a highscore board) 1 should be enough. In the name box give it any name you want(this is case sensitive) and in the "Number of fields" box put 3(this is because we will be using name,score and an unique id).

Once you hit go you will be brought to a new page to insert settings for our 3 fields. For the ease of this tutorial fill out the three fields with the information in the picture below (the field names are case sennsitive) and hit save.



Once you do that go back to the original webpage that you signed up on at the begining of the tutorial (or optionally just click this https://cp1.runhosting.com/website_manager.html). Get to the website manager tab again if your not already there and click the "Subdomain Manager" tab on the left panel.



In this section simply create a subdomain by choosing a name and "extension"(the choices in the drop down box). MAKE SURE YOUR REMEMBER IT! and hit "Add Subdomain"

Ok, were about half way done.

Next thing we want to do is click the "File Manager" tab on the left panel.

Click on the folder with your subdomain name.



For now minimize this window and open a text file.

2. PHP
Now its time for a bit of PHP . WARNING: THE SCRIPTS BELOW WILL HAVE TO BE SLIGHTLY EDITED (I will tell you what to edit)




First thing to edit, find this line (KEEP IN MIND THIS IS ALL CASE SENSITIVE)


as you can see their are two blank quotes in this function. The first one takes the database's username and the second string takes the password.

So if my database name is 12345 and password is test123 I would fill the line in like this:


The next one is simple, locate this line:


In the blank quotes just put your database name
So if my database name is 12345 I would fill the line in like this:


Ok and last thing for this script, locate this line:


This line needs to be finished off with 3 things. The name of your table, the name of your name field, and the name of your score field.

if my table name is HIGHSCORE and my name field is Name and my scoe field is Score I would fill the line in like this:


After you've done all of that save the text file as a .php script. (hit file>save as....> (choose all files for the file type) INSERTNAMEHERE.php)
Once you save it upload it to the file manager

Ok , were just about done with php. We have another small script to edit (this one does the actual returning of data)
Open a new text file and insert the following script and get ready to edit it.



The first ones easy enough because we did this with the first script
Find this line:

as you can see their are two blank quotes in this function. The first one takes the database's username and the second string takes the password.

So if my database name is 12345 and password is test123 I would fill the line in like this:


Once again this next one is easy because we did it in the first script
locate this line:


In the blank quotes just put your database name
So if my database name is 12345 I would fill the line in like this:


Ok now its time to start paying attention because these next ones might get a bit confusing so pay close attention to the examples

Locate this line



Now a space after the word FROM we need to insert the table name and after the word BY we need to insert the field name we used for our score

if my table name is HIGHSCORE and my score field is Score I would fill the line in like this:



(as a spare note this code only grabs the top 10 scores, to changes this change this line
)

Finally locate this line


in the first [''] box we want to insert the name of our name field between the '' and in our second [''] we want to insert the name of our score field

If my name field's name was Name and my Score field's name was Score my line would look like this:


Note: between the name and score there will be a | and a ; after each person's score to make things easier to separate in DBPro (so if the user's name was Sean and his score was 5 it would come out like this: Sean|5; )

After you've done all of that save the text file as a .php script. (hit file>save as....> (choose all files for the file type) INSERTNAMEHERE.php)
Once you save it upload it to the file manager

We can now run a quick test:

Go to your subdomain's url and at the end of it add a / the name of the first script we made and ?n=MyName&s=15000000
load the page ( the page will be white,just ensure that it was loaded all the way)
(mine would look like http://highscore.mygamesonline.org/dbpost.php?n=MyName&s=15000000 )

after that go to your subdomain's url and at the end of it add a / and the name of the second script we made
(mine would look like http://highscore.mygamesonline.org/dbscript.php )

You should then see the high score that you put in with the first url (if you don't then go back and ensure you followed the tutorial correctly.

3. DBPro

Ok, its time to fire up DBPro and create a new project.
(this part of the tutorial will be very brief)

Insert these two functions in your new project:



4. How to use the new functions

Now that we have our new functions in its time to put them to use.

How to send a new high score:

To send a new high score you will be calling the download function.
The first parameter of this function will take our website's subdomain along with the / the name of the first script we made and ?n=INSERT NAME HERE&s=INSERT SCORE HERE

The second parameter of this function is where we want our text file to download to (this is the file that will hold our data when we retrive it)

Example bewlow using a string (Name$) to hold the user's name and a variable (Score) to hold the user's score.


How to return high scores:

This method is pretty straight forward and we will once again be using the download function but this time we will also use the parse function.

When returning data the first parameter of the download function will take your subdomain's url and at the end of it add a / and the name of the second script we made.

The second parameter of this function is where we want our text file that contains our data to download to.



The parse function takes the string to parse,the letter/character were looking for, and how far to look. The way we setup our php script requires specific inputs for this function.

Since this is more of a straight forward thing I've posted example code below on how it should be used:



Now the end is finally in sight. Below is just some test code to make sure it all works (this is running off of my database, to test yours you should edit the first parameter in the download function)



luskos
16
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 24th May 2010 14:30
This tutorial is 10 out of 10 man.You are great.So far i can`t use it, but if i begin some biger project that actually worth to make online score board i`ll come by.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Hockeykid
DBPro Tool Maker
16
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 25th May 2010 02:26
Quote: "So far i can`t use it, but if i begin some biger project that actually worth to make online score board i`ll come by."


Yeah, at some point everyone has that game concept that involves a very competitive based scoring system.

Good luck when you get around to give it a try

Mnemonix
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 25th May 2010 03:11
I made a plugin to handle this task many years ago, and I forgot where I put it

Your signature has been erased by a mod because it's larger than 600x120
luskos
16
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 25th May 2010 13:09
Once i lost my source + the only copy of a game i made because i borrowed my memroy stick to a friend and he forget to put the backup in after he finished using it, and his cousin deleted it by mystake thinkink it`s some usless trash on his desktop.

My advice is to share anything that can have value for the comunity, it`s better than loosing it.It`s your call after all, but that`s what i do.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 25th May 2010 20:21
I remember sitting up late at night teaching you PHP and SQL to get this working! Not to mention researching the DBP code to get it working... I found the solution on these very forums, too! Can't remember who it was that posted the solution using the urlmon DLL... they should get a mention here, too, me thinks.

Good tutorial! Glad you got around to it, cuz I completely spaced out on doing it.


The one and only,


Thebeely
18
Years of Service
User Offline
Joined: 4th May 2005
Location: Croatia
Posted: 25th May 2010 21:03
I made online highscore board using FTP once This looks much better, though.
Jeff032
16
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 25th May 2010 22:45 Edited at: 25th May 2010 22:45
It's probably a bad idea to fetch the top 10 highscore the way you are doing it. You are fetching every single row in the table, and then looping through all of them, even after you reach 10 rows.

This should be faster since it only fetches the top 10 rows from the table:



(Added 'LIMIT 10' to the query, and removed the use of $x)

-Jeff

Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 25th May 2010 23:02 Edited at: 25th May 2010 23:03
I think we tried that approach, Jeff.... and I believe MySQL didn't recognize the LIMIT command. It's been a while, I could be wrong, but I do recall attempting to limit the return to only 10 within the query itself and it not working out.


The one and only,


Jeff032
16
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 25th May 2010 23:33
I had tested it before I posted. It works. Perhaps you are thinking of 'SELECT TOP 10 * FROM ..."?

Hockeykid
DBPro Tool Maker
16
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 26th May 2010 00:21
Quote: "I had tested it before I posted. It works. Perhaps you are thinking of 'SELECT TOP 10 * FROM ..."?"


No, we tested limit it didn't work.

Jeff032
16
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 26th May 2010 02:37 Edited at: 26th May 2010 02:38
Well then you must have been doing it wrong.

I followed your tutorial and have it working with this code:



-Jeff

Hockeykid
DBPro Tool Maker
16
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 26th May 2010 06:53
Quote: "Well then you must have been doing it wrong."


Yeah, I think I put it in front of the select or something like that (keep in mind at that point it was around 4:30 am). Thanks for that suggestion, I updated the first post with the change.

Jeff032
16
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 26th May 2010 16:45
You can also remove 'if ($x < 10)' and anything else using $x. That's no longer required.

-Jeff

Hockeykid
DBPro Tool Maker
16
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 2nd Jun 2010 11:10
Quote: "You can also remove 'if ($x < 10)' and anything else using $x. That's no longer required."


Fixed, thanks again for the tip.

BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Mar 2011 14:24
Springing back to life...

I have the first part of this working, thanks for the tutorial. I've added a couple of extra fields, but the script is easy to follow so editing the SQL is easy too

I also incorporated IanM's HASH MD5() command and MD5() on the PHP side to ensure nobody adds fake high scores by simply calling the address. It would be good to add this to your tutorial

DBPro:



PHP:



mr_d
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 18th Mar 2011 15:48
I've created something like this already; it's not free, but I recon is pretty cheap and good (if I don't say so myself)...
http://forum.thegamecreators.com/?m=forum_view&t=174719&b=5

(\___/)
(='.'=) Copy bunny into your signature to
("_(" help him gain world domination.
Devonps
14
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 18th Mar 2011 17:45
@hockeykid & Plystire This is an excellent tutorial, thanks guys for putting in the time and effort to make it work.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!

Login to post a reply

Server time is: 2024-03-28 14:24:20
Your offset time is: 2024-03-28 14:24:20