Jump to content


Photo

Add online highscores to your HTML5 games


  • Please log in to reply
51 replies to this topic

#41 kburkhart84

kburkhart84

    GMC Member

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

Posted 28 January 2012 - 09:18 PM

I'm not Dave :), but I can tell you that this extension was not made for what it looks like you are looking for.

My recommendation would be to learn a little PHP and MySQL. I don't know enough myself, mainly because I don't really need to learn any, but I DO know that what you want isn't that complicated once you have the basics of PHP and MySQL down.

Visit w3schools.com for a bunch of tutorials on HTML, PHP, MySQL, and a few other things.
  • 0

#42 mikebio

mikebio

    GMC Member

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

Posted 28 January 2012 - 10:58 PM

I'm not Dave :), but I can tell you that this extension was not made for what it looks like you are looking for.

My recommendation would be to learn a little PHP and MySQL. I don't know enough myself, mainly because I don't really need to learn any, but I DO know that what you want isn't that complicated once you have the basics of PHP and MySQL down.

Visit w3schools.com for a bunch of tutorials on HTML, PHP, MySQL, and a few other things.


Hey thanks for the reply! I do know PHP and MySQL quite well... but the problem is I am new to Game Maker. I just can't seem to get everything talking to each other! Actually, I have to go read some GM tutorials because I don't even know how to get text from a user! I have the "Please Enter Your Name" done but that's about it!
  • 0

#43 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9276 posts
  • Version:Unknown

Posted 29 January 2012 - 01:21 AM

The download contains a "Davejax" extension, this can be used to make the AJAX call from GM to your PHP script. You say you know PHP/MySQL quite well, have you set up scripts to retrieve and send the name and score and have it do what you want? If you have that side sorted, the GM side is not hard to set up.

To get text from a user, use the variable "keyboard_string". When the player types something, whatever they type is stored in this variable. Use draw_text to draw it's value on the screen so the player can see what they are typing.

mysql_real_escape_string() is a sanitising function to stop hacking via SQL injection. It just adds escape characters before things like ' and " so if the player tries to trick your query into doing something it shouldn't then this helps to stop it.

string_tags() stops players from entering HTML code as a name, causing the page to display differently, or injecting javascript, etc.
  • 0

#44 mikebio

mikebio

    GMC Member

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

Posted 29 January 2012 - 06:18 PM

The download contains a "Davejax" extension, this can be used to make the AJAX call from GM to your PHP script. You say you know PHP/MySQL quite well, have you set up scripts to retrieve and send the name and score and have it do what you want? If you have that side sorted, the GM side is not hard to set up.

To get text from a user, use the variable "keyboard_string". When the player types something, whatever they type is stored in this variable. Use draw_text to draw it's value on the screen so the player can see what they are typing.

mysql_real_escape_string() is a sanitising function to stop hacking via SQL injection. It just adds escape characters before things like ' and " so if the player tries to trick your query into doing something it shouldn't then this helps to stop it.

string_tags() stops players from entering HTML code as a name, causing the page to display differently, or injecting javascript, etc.


Dave do you think we can exchange email address and get this sorted out? I have tried following this tutorial as well (http://gmc.yoyogames...howtopic=520198) but still no luck. I don't need anything too complicated (as described) but I do need this for my PhD research.

I have the main page setup so that a user can enter a name and it is saved as a global variable called name (global.name). I have the database with the table called game, 2 columns (name, qc).

Basically once the user enters his/her name, I just want to get the qc value from that user name. If the name doesn't exist, then insert the name into the table. It is not that complicated, but I can't solve this with GM.

I am confused on what I need. I have a php file called dbcon.php that has
<?
   // database variables
   $dbHost = "localhost";
   $dbName = "<name here>";
   $dbUser = "<user here>";
   $dbPass = "<password here>";

   // database connection functions
   function dbConnect() {
      global $dbCon, $dbHost, $dbName, $dbUser, $dbPass;
      $dbCon = mysql_connect($dbHost,$dbUser,$dbPass);

      return mysql_select_db($dbName);
   }
   
   function dbClose() {
      global $dbCon, $dbHost, $dbName, $dbUser, $dbPass;
      mysql_close($dbCon);
      unset($dbCon);
   }
?>

What should my javascript file look like? Honestly, at this point I'll give anyone access to my DB and everything just to get this working. Thanks,

Mike
  • 0

#45 holgersson1988

holgersson1988

    GMC Member

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

Posted 22 March 2012 - 09:33 AM

This was really helpful. Is it possible to make it work from the Windows runner? Still using GM:HTML5 but running in windows mode.

Thanks for the post!

/Holgersson Entertainment¨
@HolgEntertain
  • 0

#46 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9276 posts
  • Version:Unknown

Posted 22 March 2012 - 07:13 PM

If you can use DLLs in GMHTML5 (haven't tried) then use 39DLL and check out the HTTP tutorial.

It's definitely doable in GM8. 1.
  • 0

#47 GerardoLegend

GerardoLegend

    GMC Member

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

Posted 26 March 2012 - 12:29 PM

Hi Dave!

I don't want to be of any trouble but I followed step by step your tutorial and I hit a dead end. Just to inform you before - I also have 1and1 hosting, so things are a tad bit tricky.

My issue is after I plug my ip address in with the scripts, in which are easy to follow, I'm thinking it would work out but the highscores aren't showing. Everything is in the same domain, yet I wonder if I did something wrong? The php files are in their own directory withing the same domain. As for my html5 game, even though the game is in the same domain with the scripts in its own directory, the high scores don't draw.

I did check to see if the tables had any data submitted by my test, and it looks like it does but somehow the game doesn't draw it.

again, I followed your tutorial step by step. the database is there, the tables are there, the key is there, the php with my db info is there. . . ugh.

here is your example live on my domain: My link (which is in the same directory of the php files)

I just get nothing. :confused:
  • 0

#48 GerardoLegend

GerardoLegend

    GMC Member

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

Posted 26 March 2012 - 09:13 PM

Also, When I tried to clear the php header, I didn't know exactly what should I replace it with.

I'm confused if I should replace it with header("Content-type: text/plain"); or header("location: www.darkzeta.com");

I've never programmed in PHP, and I don't know what is what even if I read about the basics, I need examples to see what does what. I see that headers have lots of definitions. which one is the right one for your highscore example if I need to replace the header with something else?
  • 0

#49 GerardoLegend

GerardoLegend

    GMC Member

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

Posted 27 March 2012 - 02:34 AM

update---

Well I finally have the database being updated by the html5/ajax/php combo! But I still don't see the results in my game.

I went in to redo step by step of the tutorial. What I messed up in the submit part is the gamed01. I got confused with with it, but now I understand it better.

update02-----

FINALLY I got it going ::lmao:: . damn. I derp really bad. Like super retarded derp that lasted 48 hours. ugh. It was a god damn typo on the address part of the getscores(); script. highscore isn't plural. lol

but I learned a valuable lesson doing this with php and game maker.

Thank you dave for the tutorial and ignoring me. lol Be on the look out for your name on the credits page/NES manual/ingame.
  • 0

#50 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9276 posts
  • Version:Unknown

Posted 27 March 2012 - 03:50 AM

Haha you posted at 1:30AM my time, then I was at work all day, and have only just got home! :P

Great to see you got it working, I probably shouldn't mention that if you want more secure high scores, you can use the Playtomic API with a wrapper extension... :whistle:
  • 0

#51 nujuat

nujuat

    Alex Tritt Games

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

Posted 26 April 2012 - 10:38 PM

Thanks a lot Dangerous Dave! I just got my new game "synced" with my new database on my new site. Hopefully I will release it soon. But yeah, thanks for the tutorial!
  • 0

#52 Vallo92

Vallo92

    GMC Member

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

Posted 01 February 2013 - 04:06 PM

Thanks!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users