Jump to content


Photo

Add online highscores to your HTML5 games


  • Please log in to reply
51 replies to this topic

#21 kburkhart84

kburkhart84

    GMC Member

  • GMC Member
  • 1646 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
  • 9282 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

    GMC Member

  • GMC Member
  • 1646 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
  • 9282 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

    GMC Member

  • GMC Member
  • 1646 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
  • 9282 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

    GMC Member

  • GMC Member
  • 1646 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
  • 9282 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

    GMC Member

  • GMC Member
  • 1646 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

#31 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9282 posts
  • Version:Unknown

Posted 07 December 2011 - 04:32 AM

Some browsers just down support cross domain requests, so as much as YoYo may want to have a database set up for everyone to use, it's just not going to work. I doubt they are working on HTML5 online highscores, and I would rather their efforts were placed elsewhere.

As for the PHP scripts, yes, there's heaps of additional things you could get it to do, this tutorial is just to get you started ;)
  • 0

#32 kburkhart84

kburkhart84

    GMC Member

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

Posted 07 December 2011 - 02:52 PM

Some browsers just down support cross domain requests, so as much as YoYo may want to have a database set up for everyone to use, it's just not going to work. I doubt they are working on HTML5 online highscores, and I would rather their efforts were placed elsewhere.

As for the PHP scripts, yes, there's heaps of additional things you could get it to do, this tutorial is just to get you started ;)


Actually, I was figuring Yoyo could use SQLite if they wanted to implement the thing. It wouldn't work cross-domain either most likely, but it doesn't require a database, rather creates a file in the server space, so it would make sense for them to do it that way. I agree that there are better things they can and should be doing though.
  • 0

#33 True Valhalla

True Valhalla

    ಠ_ಠ

  • Retired Staff
  • 4938 posts
  • Version:GM:Studio

Posted 11 December 2011 - 01:41 AM

I've never really understood the appeal of stand-alone high score systems like this, because they are too vulnerable to exploitation. Are there any counter-measures which stop clients sending fake scores..? Is that even possible without server side verification of their game session along their way?

I'd love to use this, but a flaw like that can make high score systems pointless.
  • 0

#34 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9282 posts
  • Version:Unknown

Posted 11 December 2011 - 02:33 AM

The highscore itself is encrypted to some extent. The name is sent in plain text. To be able to submit a score, the user needs to know the security key, which GM does a good job of hiding with it's obfuscation.

One thing that could be added is a system to check that the score hasn't already been submitted, which is kinda half set up. Currently the system stores the code used for submission, but something would need to be added to stop the same score having the same code. I'd probably add the linux time stamp (or some other date) to the score, so you would submit string(score)+"|"+timestamp. The system already has the ability to include the | in the string being encrypted. You would then take the output and split off the score in the PHP script, and also check that the same code hasn't already been submitted.

That would stop the same code being used to submit the same score multiple times, but not stop the same score being submitted twice if it were earned. It would also make the encryption slightly harder to hack, as it introduces something which the player has no knowledge of it's value.

That's about as good as I know, but I'm not sure if much else can be done without moving everything client side (which would probably be too slow for an HTML5 game).

Personally, I haven't had any trouble with hackers (that I know of :whistle:). I'd look into further options if it became an issue.

In reality, it's risk free. If people hack it, I'll delete the cheat scores. If lots of people hack it, I'll just remove the online high scores. But why not have online high scores if it encourages more people to play? There's no money at stake, the most I have to lose is the online highscores, which I otherwise wouldn't have added. I really don't understand why you would shy away from them simply because of the potential actions of a few?
  • 0

#35 True Valhalla

True Valhalla

    ಠ_ಠ

  • Retired Staff
  • 4938 posts
  • Version:GM:Studio

Posted 11 December 2011 - 02:51 AM

I really don't understand why you would shy away from them simply because of the potential actions of a few?


They're the ones that you need to watch out for though ;) Of course, for high scores it's not really a big issue.
  • 0

#36 metaaldetectie

metaaldetectie

    GMC Member

  • New Member
  • 4 posts

Posted 01 January 2012 - 02:14 PM

The high score works fine only I find it annoying that if you don't fill in a name you have an empty field.

Is there a possibility with gml or php to require filling out a name, so you have to fill in something.
  • 0

#37 kburkhart84

kburkhart84

    GMC Member

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

Posted 01 January 2012 - 06:09 PM

The high score works fine only I find it annoying that if you don't fill in a name you have an empty field.

Is there a possibility with gml or php to require filling out a name, so you have to fill in something.


Why don't you do it the easy way? In the script where you are receiving the name, when enter is pressed, make sure it is not empty. If it is, either do nothing(expecting a name), display a message that they need to type a name, or simply put a substitute. You do this in the gml, not in the PHP, simply because it is easier than modifying the PHP, unless you know what you are doing.
  • 0

#38 metaaldetectie

metaaldetectie

    GMC Member

  • New Member
  • 4 posts

Posted 01 January 2012 - 08:24 PM

when enter is pressed, make sure it is not empty. If it is, either do nothing(expecting a name), display a message that they need to type a name, or simply put a substitute.


Can you give me an example in gml?
  • 0

#39 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9282 posts
  • Version:Unknown

Posted 01 January 2012 - 11:03 PM


if (global.name != "")

{

  submit();

}

else

{

  show_message("Please enter your name");

}


  • 0

#40 mikebio

mikebio

    GMC Member

  • New Member
  • 18 posts
  • Version:GM:HTML5

Posted 28 January 2012 - 08:36 PM

This all seems a bit too complicated. I just purchased this with hopes that the game I am trying to make would be less complicated but now I am not too sure.

I want a homescreen that the user can enter his/her name and then hit go. If the name exists in a database, then it will pull up the users previous score. If not, then it will create the user with whatever name was entered.

This is being done as a closed study, and that is why I do not have a password.

Can you help with this Dave? You seem to know what you are talking about! I have the DB and table created (with 2 columns: name, score). I am just confused on the whole GM extensions and scripts and like I said, it all seems too complicated. I read your code but just couldn't understand a lot of it (such as strip_tags(mysql_real_escape_string))

Hope you can help,

Thanks,
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users