Jump to content


Photo

Add online highscores to your HTML5 games


  • Please log in to reply
57 replies to this topic

#1 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 29 November 2011 - 04:59 AM

Before you start: I highly recommend you use my newer tutorial for more secure highscores: http://gmc.yoyogames...howtopic=538699

Dave's HTML5 Highscore Tutorial

Due to so many people asking how it's done, I've decided to make a tutorial so you can make your own highscores in your HTML5 games!

What you need:
-GameMaker HTML5
-This resources pack (updated 4/12/11) (note that this tutorial is included in a text file in this pack)
-Half decent GML knowledge

What you might want:
-A webhost that supports PHP and MySQL (these instructions assume a PHPMyAdmin interface)
-Some PHP knowledge if you want to alter anything

If you don't have your own web host, you may run into some problems. Notably, if your high score server and your game are located at different domains, the game wont work in IE or Opera.

Steps 1 and 2 talk you through setting up your own server. If you don't have one, then let me know and I'll set you up on my database. Then skip to step 3.

Step 1 - The database

Due to each host having a different method, you'll need to create the database yourself (Table structure is included in this tutorial, just not creating the initial database). Hosts have many different ways of doing this, so I can't include all options. You might want to start somewhere near a "MySQL" button.

Once you've got your database created, you need to create the tables by importing the SQL file from the resource pack. Open PHPMyAdmin, and click "Import". Upload the file in the appropriate box and click "Go".

This will set up the tables used for storing the highscores and the game info. You need to set up a game in the gamet01 table. To do this, choose the html5_db database from the list on the left (it may have done this automatically depending on your host and PHPMyAdmin version). Next, click gamet01 in the same area.
Next, click the "Insert" tab in the right hand panel.

In the namet01 box, put the name of your game, say, "Game 1".
In the keyd01 box, put an encryption key. This needs to be exactly 15 characters long, letters only (preferably capitals), and non-repeating (you can't have the same letter occuring twice in the string).
Leave the other boxes blank (they will auto-fill) and click "Go".

That's the database set up. Next, time to work on interfacing with the database.

Step 2 - PHP scripts

In the resources pack are three PHP scripts, mysql.php (more on this later) getscores.php and submitscore.php. The latter two should be uploaded to your web server, and be sure to remember the URL as you'll need this later. mysql.php needs some changes before you upload it, as outlined below. Be sure all three scripts are in the same directory.

The mysql.php file contains the details required to connect to your MySQL server. The required details can be provided by your host. The details you need are the MySQL server location (host), your user name, and your password.

I haven't gone into details with the PHP scripts, but if you have any questions then let me know (unless your question is about the encryption, because even though I wrote it, I don't understand it, it was all done through trial and error).

Step 3 - The game

Included in the resources package is an example game, Davescores.gmz. Import this game into GMHTML5 by clicking Import GM81 on the welcome screen. Choose "*.gmz" from the dropdown box, and select the Davescores.gmz file.

I've found when I import a game the extension plays up. To make sure it works, right click on it and delete it. Then right click, add existing extension, click the Install button, then Install, then choose Davejax.gex. Click OK, choose the Davejax extension and click the arrow to add it to the project. It should work fine from there.

The GM file has a fully working example, showing how to submit scores and retrieve highscores. By default, it's set to link to my database. You can update it to work with your database by changing the following settings:

Scripts:

getscores
-change URL on line 7 to the location of your getscores.php file.

submitscores
-change key on line 3 to your encryption key
-change URL on line 7 to the location of your submitscores.php file.

Objects:

viewscores
-create event: Change first argument of getscores() function to the ID number of your game (The value of idd01 in your gamet01 table entry, probably 1 if it's your first entry)

drawsubmit
-press <enter>: Change first argument of submitscores() function to the ID number of your game


And that's it! After changing those values, test out the game and see if it loads and submits to your database OK. It may have lots of 0's or say "undefined" until you get 10 entries in the database for your game. Make sure you always submit at least 10 scores before going public with the game.

Once you've got the example working, you can work on adding it to your own game. I'll leave that one up to you.

Cross domain requests

It's important to note that some browsers do not allow cross-domain AJAX calls. What this means is that if you are in certain browsers, then it wont work unless the game is hosted on the same domain as the PHP scripts you are calling with AJAX. So if you had your game on your site, but it was sending the highscores to my database, most browsers would block this activity by default.

The reason is that if you log into a website, say facebook, then visit my malicious site, I could make an AJAX call that brings up facebook and posts a status. I wouldn't need to make my malicious site log in, because the browser already has a cookie that says I'm logged in, so facebook would let my (potentially) malicious script in to wreak havoc.

All browsers stop this activity by default, but you can send a header on the server that tells the browser to allow access. In the above example, the site sending the header would be facebook, which would say "let in requests from other domains". Obviously facebook doesn't allow this so they don't send that header, but for some sites this is needed, so they do send the header. It's possible to select which source domains are allowed to connect, too. The PHP scripts above both have this header being sent. If you will only ever have your games on the same site as the PHP files, then it may be a good idea to remove the "header(...)" line from the PHP scripts.

Anyway, these headers only work on certain browsers. In my experience, Chrome, Safari, and Firefox do work (if the header is inluded in the PHP file, all major browsers block it without the header), Opera and IE do not work with or without the header.

So if you want to avoid problems, host your PHP scripts on the same site as the game will be played on.

It's also possible to use a PHP proxy script, that tricks the browser into thinking the request came from the same domain, but that's outside the scope of this tutorial.

PLEASE NOTE: http://www.example.com and http://example.com are *different* URLs. Always be consistent in which one you use (I suggest always starting with www).

My webhost has a setting it calls hard canonical, which means that if someone tries to go to http://example.com it forces the site to switch to http://www.example.com. Your host might have it too. If it does, I'd consider switching it on.

Final words:

Hopefully this tutorial has been enough for you to set up highscores for your game. If you have any questions, let me know!

Thanks for reading!

-Dave

PS: I'm very interested in suggestion on improving the tutorial or my code (especially the encryption code). So if you have a question, suggestion or complaint then let me know!

PPS: I'm looking for some more games to add to my website http://www.html5haven.com so if you think your game is at least as good as the others on there, let me know and I'll add yours too :D.

Edited by Dangerous_Dave, 02 May 2012 - 06:24 AM.

  • 4

#2 Desert Dog

Desert Dog

    GMC Member

  • Retired Staff
  • 6409 posts
  • Version:Unknown

Posted 29 November 2011 - 05:25 AM

Sweet!

First!

Pow!

Now I can make my own highscores, and disown you! :D
  • 0

#3 Psalms23

Psalms23

    GMC Member

  • New Member
  • 163 posts

Posted 29 November 2011 - 07:08 AM

Thanks for posting this, I was wondering how this is done. Seems a little complicated for up novices but I'm sure with a careful following of the steps we'll get it
  • 0

#4 haloflooder

haloflooder

    GMC Member

  • GMC Member
  • 35 posts

Posted 02 December 2011 - 06:17 AM

Wow, this is the best online score tutorial for HTML5 atm.

But I have a problem. phpmyadmin says this whenever I try to import the database file
Spoiler

Edited by haloflooder, 02 December 2011 - 06:18 AM.

  • 0

#5 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 02 December 2011 - 03:25 PM

Wow, this is the best online score tutorial for HTML5 atm.

But I have a problem. phpmyadmin says this whenever I try to import the database file

Spoiler


I'm getting the exact same error. I tried to change the default character set of the file(to import it) to latin1, since that is in the error message, and I get the same thing.

EDIT** I'm noticing that when I use WinRAR to extract/view the files, it appears that the "endline" character is not working right. For example the mysql.php file comes across like this if I copy/paste into this quote box.

<?
//X Y and Z are details you need to get from your host
$dbHost = "X";
$dbUser = "Y";
$dbPass = "Z";
$dbDatabase = "html5_db";
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db($dbDatabase);
?>


But if I copy/paste or just leave it alone in notepad(I'm on windows 7) the lines are all bunched together.

<?
//X Y and Z are details you need to get from your host$dbHost = "X";$dbUser = "Y";$dbPass = "Z";$dbDatabase = "html5_db";$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die "Error connecting to database."); mysql_select_db($dbDatabase);?>


It may stupidly be some issue with text editors and character sets. But I don't know enough about that to figure it out at this time.

I would have thought that using PHPMyAdmin would have it automatically connect and select the database before sending the queries to create the tables, but apparently it didn't in our case.

Assuming that the lack of endline symbols in notepad were not the issue, a solution would be to figure out why the database isn't getting selected. Using the actual intended query, we could run a PHP file(that actually selects the DB) to do it manually instead of using PHPMyAdmin, but with the endline errors, I'm not sure what I need to move where to get this to happen.

EDIT AGAIN***

I was able to get PHPMyAdmin to create the tables for me, using that same .sql file. Originally I was importing the file on the left side, and(at least in firefox) it was bringing up a little window to import the file. But, if you click on the name of the database on the left side, it brings up the structure/etc... on the right side, and then if you click on the "SQL" tab on that is on the top, and follow the same procedure(like you were trying to do in the little window) importing the file, it works, and suddenly you now have the two tables you need.

Edited by kburkhart84, 02 December 2011 - 08:03 PM.

  • 0

#6 haloflooder

haloflooder

    GMC Member

  • GMC Member
  • 35 posts

Posted 02 December 2011 - 10:02 PM

ok, I also imported the tables into the database. I just created a database "html5db" and just import the file from there. :)
  • 0

#7 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 02 December 2011 - 10:21 PM

EDIT** I'm noticing that when I use WinRAR to extract/view the files, it appears that the "endline" character is not working right. For example the mysql.php file comes across like this if I copy/paste into this quote box.
...
It may stupidly be some issue with text editors and character sets. But I don't know enough about that to figure it out at this time.

It appears like that because it isn't using Windows line breaks. Once uploaded to your server it will be fine.

I was able to get PHPMyAdmin to create the tables for me, using that same .sql file. Originally I was importing the file on the left side, and(at least in firefox) it was bringing up a little window to import the file. But, if you click on the name of the database on the left side, it brings up the structure/etc... on the right side, and then if you click on the "SQL" tab on that is on the top, and follow the same procedure(like you were trying to do in the little window) importing the file, it works, and suddenly you now have the two tables you need.

My PHPMyAdmin doesn't appear to have a "Import" button on the left, only on the right, further along from where the "SQL" tab is.

ok, I also imported the tables into the database. I just created a database "html5db" and just import the file from there. :)

Ah, so you need to create a database before you import? I didn't realise, I'll add that into the tutorial.

Thanks for testing it out guys :)

Edit: On further testing, my SQL file is slightly wrong. I've uploaded a new version of the resources folder, so any future people wont have to create the database separately.

Edited by Dangerous_Dave, 02 December 2011 - 10:37 PM.

  • 0

#8 haloflooder

haloflooder

    GMC Member

  • GMC Member
  • 35 posts

Posted 02 December 2011 - 10:47 PM

I have a question about the GML arguments
Lets say I named the game in my database GBRA as my first game
Do I put use
getscores("GBRA", 5, true); and submitscores("GBRA", 5, true);
or
getscores(1 , 5, true); and submitscores(1 , 5, true);

EDIT*
oh, and another question.
What does the score/name look like in the highscore table?
I want to manually import a score to see if it actually works on my game

Edit**
lol... and another question
Lets say I want to load the lowest score (lets say the 100th score) without having to load the first 99 scores. How do I do that?

Edited by haloflooder, 02 December 2011 - 10:57 PM.

  • 0

#9 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 02 December 2011 - 11:18 PM

The game name in the database is not actually used, it's just there so when you open up the database, you can tell which ID is for which game. You use the idd01 of the game, the second option you listed.

The score in the database only has three important values.
gamed01 is the ID of the game. This is used so we only need one table to store highscores for an unlimited number of different games.
scored01 is the score the player got.
named01 is the player's name

The other columns either auto-fill, or are not strictly necessary.


The scores are not capped, every score is kept indefinitely. If you want to load the lowest score ever, you can change the order of the highscores. Open up the viewscores object in the example, and change the arguments of getscores. Currently it looks like this:

getscores(2, 5, true)

The first argument is the game ID, so you probably want to change this to 1 (if you followed the tutorial, you've done this). The second argument is how many scores to return. If you just want the lowest score (rather than the 5 lowest scores), put 1. The third argument is the order. true gives you the highest scores, false gives you the lowest.

It's currently not possible to retrieve just the nth score, only a certain number of the highest or lowest. If you wanted the 100th, you'd have to load 100 scores, then pick the last one.

Edited by Dangerous_Dave, 02 December 2011 - 11:56 PM.

  • 0

#10 haloflooder

haloflooder

    GMC Member

  • GMC Member
  • 35 posts

Posted 03 December 2011 - 12:29 AM

Thanks! but you didn't answer one of my question.
Q1:
Is it possible to manually put in the score via PHPmyAdmin? I would like to do this to see if my game is displaying the scores or not when I'm trying to get it to work.

Q2:
Also, in the mysql.php file. Do I just put in "$dbHost = "sub.domain.com"" or "$dbHost = "sub.domain.com:port""?

I'm having trouble getting this to work :/ whenever I push submit, it doesn't execute the codes in the script for some reason. There is nothing wrong with the GML coding either.
This is what I have in the mouse left pressed event
Spoiler

  • 0

#11 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 03 December 2011 - 12:37 AM

1: Sorry, yes it's possible, you open the table and click the "insert" button, then fill it out as I described in my previous post.

2: It varies from host to host. For example, with my host it's "username.db", some hosts it's "localhost" and in others it's a domain, sometimes with a port. The information should be somewhere in your host's control panel, probably somewhere near where you set up mysql.

Try visiting the mysql.php file in your browser (ie yourdomain.com/mysql.php ). This should show as blank (as it is just connecting, and doing nothing else). It may display an error instead.
  • 0

#12 haloflooder

haloflooder

    GMC Member

  • GMC Member
  • 35 posts

Posted 03 December 2011 - 01:09 AM

Oh, I'm blind. haha. I didn't see that in your previous post for some reason. I'm sorry. haha

Well, I'm hosting it myself and I put my ip in the subdomain and the port number is 3306. So do i use <sub>.hhcraft.info:3306 for my host? and if the php page is blank with no error, it's good to go right? and what is hitst01 used for?

Even though I put the highscore in the database manually. The scores still don't show up on my game. I don't know what's going on. I checked everything and they look fine... I'll go make my game grab some scores from your database. If that doesn't work then I guess I have to find another way to fix it.


EDIT***
I got it working!

I'm sorry that I'm asking A LOT of questions. I just really want to add a highscore feature in a game I'm developing and I'm just getting some trouble setting it up even though I use mySQL and GM everyday :/

Thank you very much for helping me! You have shown me the light.

Edited by haloflooder, 03 December 2011 - 02:22 AM.

  • 0

#13 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 03 December 2011 - 02:34 AM


EDIT** I'm noticing that when I use WinRAR to extract/view the files, it appears that the "endline" character is not working right. For example the mysql.php file comes across like this if I copy/paste into this quote box.
...
It may stupidly be some issue with text editors and character sets. But I don't know enough about that to figure it out at this time.

It appears like that because it isn't using Windows line breaks. Once uploaded to your server it will be fine.

I was able to get PHPMyAdmin to create the tables for me, using that same .sql file. Originally I was importing the file on the left side, and(at least in firefox) it was bringing up a little window to import the file. But, if you click on the name of the database on the left side, it brings up the structure/etc... on the right side, and then if you click on the "SQL" tab on that is on the top, and follow the same procedure(like you were trying to do in the little window) importing the file, it works, and suddenly you now have the two tables you need.

My PHPMyAdmin doesn't appear to have a "Import" button on the left, only on the right, further along from where the "SQL" tab is.

ok, I also imported the tables into the database. I just created a database "html5db" and just import the file from there. :)

Ah, so you need to create a database before you import? I didn't realise, I'll add that into the tutorial.

Thanks for testing it out guys :)

Edit: On further testing, my SQL file is slightly wrong. I've uploaded a new version of the resources folder, so any future people wont have to create the database separately.


As far as an import button on the left, there isn't one directly. Right next to the little "house" button, there is an SQL button, which opens up a little window, which then has the import option which tries to execute the SQL query without having the database selected first. But if I do it on the right side, it works fine.

About the line breaks, I figured that was the case. One, I remember the original kit you offered to me through PM had been zipped on MAC OS, and two, when I copy/pasted it to put it on the forum here in a quote, the line endings worked, though they didn't if I pasted to another text document.

About the need to create the database...I understand that php can do that through code, but it seems that I read somewhere that some hosts don't let that happen. For example 1and1 is supposed to be bad about that, and I happen to have 1and1 for my webhost, though it hasn't given any problems yet. Through the 1and1 administration site, I can access PHPMyAdmin through the MySQL database admin section. But, the button is only there if you actually have created a database. In their FAQs they mention a procedure to manually install PHPMyAdmin, but it seemed easier to me just to create the database through 1and1(though they gave it some crap name like st0000000) and then just use that. So, you may want to explain those details if/when you add the database creation to the tutorial because I'm sure other webhosts have some of the same issues.
  • 0

#14 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 03 December 2011 - 06:44 AM

I've updated the SQL file so that when you import it via PHP, it automatically creates the database. This doesn't happen through PHP. If you haven't got it working yet, download the updated resources folder then follow the tutorial, it should work from there.
  • 0

#15 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 03 December 2011 - 08:12 PM

I've updated the SQL file so that when you import it via PHP, it automatically creates the database. This doesn't happen through PHP. If you haven't got it working yet, download the updated resources folder then follow the tutorial, it should work from there.


I don't think it would work, in my case at least, because I can't access MyPHPAdmin without having actually created a database first. That's why I mention maybe if you update the tutorial you might want to mention that because 1and1 probably isn't the only host like that.

At the least, for personal use, I'm thinking of taking the gml functions for this and sticking them into an extension, and simply adding the encryption key as an argument. I doubt you'd have a problem with me doing it for personal use, but would you mind if I released it here. I'd be glad to give it to you so you could keep all of it together, or I wouldn't mind putting it up myself either way. Of if you'd rather me not, I'll just keep it for personal usage. What do you think??
  • 0

#16 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 04 December 2011 - 01:55 AM

I don't think it would work, in my case at least, because I can't access MyPHPAdmin without having actually created a database first. That's why I mention maybe if you update the tutorial you might want to mention that because 1and1 probably isn't the only host like that.

Ah, I see. Do you know what happens if you try to load the SQL file I uploaded? Does it create a second database? Does it fail with an error?

At the least, for personal use, I'm thinking of taking the gml functions for this and sticking them into an extension, and simply adding the encryption key as an argument. I doubt you'd have a problem with me doing it for personal use, but would you mind if I released it here. I'd be glad to give it to you so you could keep all of it together, or I wouldn't mind putting it up myself either way. Of if you'd rather me not, I'll just keep it for personal usage. What do you think??

Go nuts, mate. You can change, improve and even deprove if you want. Release away.
  • 0

#17 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 04 December 2011 - 03:56 AM

I get this error.

#1044 - Access denied for user 'dbo393690342'@'%' to database 'html5_db'


To even try this, I created a "test" database. Then I opened up PHPMyAdmin with that database. Then I tried to import that SQL file, and it spit that error. Remember I can't open PHPMyAdmin without having created a database through 1and1's administration site, so the error pretty much makes sense.

About my creating an extension out of the gml functions, I think I'll probably just leave it alone as is. I'll likely save out the functions with my changes(dbname, encryption key, url, etc...) so I don't have to import and change that everytime I create a new game. Plus most games won't be using the objects that you already have set up in your test project, rather they will only need the gml scripts. Thanks for the permission though.
  • 0

#18 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 04 December 2011 - 04:11 AM

Thanks for testing that, I think it might be better to change the tutorial to include creating the database, then remove that part from the SQL file. That way it covers both situations.
  • 0

#19 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 04 December 2011 - 04:15 AM

Thanks for testing that, I think it might be better to change the tutorial to include creating the database, then remove that part from the SQL file. That way it covers both situations.


That makes sense...but I think if you explain it, you might be fine having both versions. That way, the ones who can do it the easy way(like you originally intended) can do it. And the ones who can't can do it the "harder" way. You might even create a list of confirmed hosts that have to be the harder way, with 1and1 being the first.
  • 0

#20 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 04 December 2011 - 05:19 AM

To be honest, I have no idea how common it is that you can just load the SQL How I exported (obviously it works with my host, but I don't know about others). I think getting people to setup their own database, and just having the tables created via import is a better option. I used a few free hosts a few years ago, and I seem to remember them each having a different way to create a database.

I think I'll just get people to set up their own database, and then they can load the SQL from there. It seems like the best option to incorporate all hosts.
  • 0

#21 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 04 December 2011 - 06:31 AM

I see the point. Indeed there may be too many different things.

One thing I'd recommend is maybe having that SQL query(for creating the tables) be also in the form of a php script executing the query. The reason is because some hosts may not even have PHPMyAdmin, and/or it may actually be easier to upload a php script to the server and navigate a browser to it.

The other problem I see is that some hosts may not have an SQL Database Administration tool, rather may be set up to only allow modification through actual code directly, including even DB creation. Hence my above suggestion may be even more necessary. The issue is that there are too many different possibly situations and hosts, and even different hosting contracts within the same host, and so it is difficult for you(as the person providing the tutorial/kit) to accomodate all of that.

Thanks again for the help. I've never learned "internet programming" having only worked with traditional programming from QBasic to C++, and now GM. I understand some concepts of how internet programming works, but I'm not capable at this time of doing what you have done here(as simple as it actually is) so I appreciate it.
  • 0

#22 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 04 December 2011 - 08:31 AM

Running the query through PHP is as simple as putting it in a mysql_query("query here"); function. I feel like the situations in which the tutorial doesn't fit are so few, that I'd rather have people ask questions for me to answer than make the tutorial more complicated.

It's good to see you get help out of it, if you have any more questions, be sure to ask :)
  • 0

#23 haloflooder

haloflooder

    GMC Member

  • GMC Member
  • 35 posts

Posted 06 December 2011 - 12:43 AM

Sorry about bothering you again but I have one more question.

Is it possible to pull out dates? So I can do Top Monthly score, Top Daily Score, etc
  • 0

#24 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 06 December 2011 - 02:46 AM

Sorry about bothering you again but I have one more question.

Is it possible to pull out dates? So I can do Top Monthly score, Top Daily Score, etc


This tutorial doesn't have anything directly on it. I don't know enough to explain how, but I'm sure if you study up on some SQL, specifically how queries work, you could make a php script that does it. Then you could use the same function that is in the ajax extension(part of the tutorial) to call that php script.
  • 0

#25 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 06 December 2011 - 06:19 AM

Is it possible to pull out dates? So I can do Top Monthly score, Top Daily Score, etc

Not by default. If you want to do that, you'll need to add an extra mysql query (or a new PHP script to pull the value).

The SQL would look something like this:
$result = mysql_query('select * from highscorest01 WHERE gamed01=1 and timestampd01 >= DATE_ADD(CURDATE(), INTERVAL -1 MONTH) order by scored01 desc limit 1');

That will grab the top score over the past month.
  • 1

#26 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 07 December 2011 - 12:31 AM

You might want to know...my two HTML5 games on www.firehammergames.com are now high score enabled. The system so far works great, and I will be using it for all of my HTML5 games coming up, unless GM suddenly gets some internal capability rivaling the ease of use of this one.
  • 0

#27 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 07 December 2011 - 03:22 AM

On Hungry (whose page title says "Interstellar cleanup") it's got a top highscore thing when if first loads, but it doesn't load the same scores as when you submit. Other than that, it works good :)
  • 0

#28 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 07 December 2011 - 03:37 AM

On Hungry (whose page title says "Interstellar cleanup") it's got a top highscore thing when if first loads, but it doesn't load the same scores as when you submit. Other than that, it works good :)


About the title, ouchie, I copied the page so it would be easier to get the HTML5 working with my editor, and forgot to change the name.

About the scores, that is kind of remnants of what was done before I actually added your high score system. It would show the highest score in a players "session" but had no connection with the high score database because it didn't exist at the time. Normally you should be taken there after seeing the high score table, but since the objects detect keys being down it ends up "skipping" that room and going back to the game again. I will fix this, but I was in a hurry to get the games working with the high score database since I had a little time today. That is kind of what happens when I do high scores as an "add-on" after having made the game. At least in this case it was only two games. When I rework them, I will have a better title screen, and have where you actually click a button so from the title screen you can see the high score table. I think I would also make it not force you to input a name, and instead only ask for it if you score above the 10th spot.

Did you notice that I included a backspace event, so you could go fix it if you made a mistake typing. I'm using the same "quick" solution to grab keyboard input as you used in your tutorial of this topic. But it has some problems, for example didn't originally include the backspace thing. It also seems like only letters work right, but I haven't fully tested it.
  • 0

#29 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 07 December 2011 - 03:50 AM

The example file was actually created really early on, when GMHTML5 didn't support keyboard_string. When I make games, I make the interface separately, then just copy the couple of scripts over, so I forgot it was using the workaround way to accept keyboard typing.

When I wrote a highscore system while porting a friend's game to Mac, I actually had the PHP script return your place in the highscores (whether it be 3rd or 300th). I didn't do it for my HTML5 one because I had it return error numbers instead while I was trying to get it going. It's really just a small tweak in one of the PHP scripts to have it return your place, so I might do that at some stage.
  • 0

#30 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 07 December 2011 - 04:09 AM

The example file was actually created really early on, when GMHTML5 didn't support keyboard_string. When I make games, I make the interface separately, then just copy the couple of scripts over, so I forgot it was using the workaround way to accept keyboard typing.

When I wrote a highscore system while porting a friend's game to Mac, I actually had the PHP script return your place in the highscores (whether it be 3rd or 300th). I didn't do it for my HTML5 one because I had it return error numbers instead while I was trying to get it going. It's really just a small tweak in one of the PHP scripts to have it return your place, so I might do that at some stage.


Sounds like a winner. I was actually considering a few extra things myself. For example, I think I should modify/recreate the submission script so that the score is provided in an argument instead of directly coded as "score." Some people don't use that built-in variable, and would have to modify the script to do it. Also, the PHP side could use a method to return a given span of scores(say from 10 to 20th), and/or things like dates/times(like the other poster mentioned). The only thing that gets me is I'm wondering if/when Yoyo implements high scores into GM internally, how would they work, and what capability would they include. It just feels like we may be inventing the wheel they already have in the works. Who knows??
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users