Jump to content


Photo
* * * * * 2 votes

[GMHTML5/GMS] User Login/Game Saving PHP


  • Please log in to reply
14 replies to this topic

#1 Destron

Destron

    GMC Member

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

Posted 31 March 2012 - 03:07 AM

  • Title: User Login/Game Saving Using PHP/MySQL/Asynchronous
  • Description: Detailed example of how to create a user account, log in, and save/load info using async functions.
  • GM Version: :GMHTML5: :GMS:
  • Registered: Yes
  • File Type: .zip
  • File Size: 1.44MB
  • File Link: My Link | Live Example
  • Required Extensions: None
  • Required DLLs: None

Summary

You can view the example live here: Async Live Example

This is a detailed example of how to use Asynchronous functions to communicate with a PHP script. This example shows you how to create a new user account, login to said account, save information to the database, and pull that information back out of the database and load it in the game. You do not need to know PHP to use this, you just have to understand what edits to make to the included PHP file and that is completely detailed through comments in the files themselves and the included PDF.

If it is warranted, I will continue to develop and add functions to this example.

The archive includes:

The .gmz project file for GM:HTML5 or GMS
The sample complied website
The PHP script that contains the functions you will call
A .sql file with a sample database to get you running fast for experimentation.
3 PDF files, a Quick Setup guide, A guide that details all the PHP code, and a guide that details the GM parts.

Required:
PHP/MySQL enabled Webhost
Ability to create and modify a database on your webhost
FPT client
Notepad or other NON rich text editor (I suggest notepad++)
Ability to read

Potential additions:
* Reset user password via email
* Function that pulls more than one row of data
* Example of a "High score" list.
* Anything else you would like to see added.

Spoiler

Edited by Destron, 27 June 2014 - 09:46 PM.

  • 7

#2 Joe H

Joe H

    GMC Member

  • GMC Member
  • 352 posts
  • Version:Unknown

Posted 25 April 2012 - 04:05 PM

This is a really great tutorial. The amount of documentation and the clear examples earned a +1 from me. Thanks for this, it was an unexpected find and will go a long way to helping further my understanding of using a database with GM.

This should be considered for Staff Choice IMHO.
  • 0

#3 jmorrissey

jmorrissey

    GMC Member

  • New Member
  • 23 posts

Posted 02 May 2012 - 04:25 AM

This is a really solid walkthrough. It covers every step you'll need to know, including what to do on your server when setting up the MySQL database. It's well worth downloading for anyone wanting to be able to read and save data from a website for save/load game information.
  • 0

#4 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 21965 posts
  • Version:GM:Studio

Posted 06 May 2012 - 09:02 PM

Excellent Tutorial. Im moving this to the Staff Pick...
  • 0

#5 Lordfef

Lordfef

    GMC Member

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

Posted 12 August 2012 - 01:55 PM

Excellent Tutorial. Im moving this to the Staff Pick...


I agree, very useful! good job. Thank you very much for this.
  • 0

#6 Jezzarb94

Jezzarb94

    Occasionally a bag of d--

  • GMC Member
  • 78 posts
  • Version:Unknown

Posted 13 August 2013 - 02:04 PM

anyone know hy im just getting error message on the page?


  • 0

#7 Destron

Destron

    GMC Member

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

Posted 14 August 2013 - 07:15 PM

If you could give some more details maybe we can help you
  • 0

#8 camerakid

camerakid

    GMC Member

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

Posted 03 September 2013 - 08:38 PM

EDIT: Now it works fine. I missed a step that I should use the exactly same URL path with all the extra characters in the end!

 

It gives me also an "error" message only... and I do not know what more details can I put here.

 

I followed all instructions however, in my MySql system it reads:

 

"Your PHP MySQL library version 5.1.49 differs from your MySQL server version 5.0.45. This may cause unpredictable behavior."

 

Shall I update any of these maybe?

 

Your help would be really great, thanks! :-)


Edited by camerakid, 03 September 2013 - 09:00 PM.

  • 0

#9 BobFish

BobFish

    GMC Member

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

Posted 28 October 2013 - 11:41 PM

This tutorial looks very cool! I will be checking it out later and I'll tell you how I go.


  • 0

#10 gearmex

gearmex

    GMC Member

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

Posted 23 December 2013 - 12:24 PM

seems the links are dead?


  • 0

#11 tom713

tom713

    GMC Member

  • GMC Member
  • 19 posts

Posted 30 March 2014 - 08:26 AM

Hi Destron. 

Thanks for thoses explanations. I tried to make an online score table since few days, but didn't progress at all. i jump from ruby (excellent tuto by game geisha, but with two things I can't manage for now) to php.

Your document is very clear.

However, I hit the "Can not connect to server" message when I put the php file online to make a direct test (without involving gamemaker) with the mySql database.

I tried different things without success. I am pretty sure the password and username are good.

 

When I run the "http://www.mydomain....=ts&pname=Admin" adress in my browser (with a good domain name), I got a message error about the line 21 :

 

$con = mysql_connect($mysql_server,$mysql_username,$mysql_password) or die('Can not connect to server');

 

After few hours I read on a php manual that the "mysql_connect" is now obsolete. I am not sur about what to use instead (I am a total newbie in Php).

http://www.php.net/m...sql-connect.php

 

I don't know what to do, does I have to change the mysql_connect to something else ? I think the problem should come from something else but actually, I feel a bit lost. I will have probably to check the php forum (and beginner guide) rather than gamemaker -_-


  • 0

#12 tom713

tom713

    GMC Member

  • GMC Member
  • 19 posts

Posted 30 March 2014 - 09:21 PM

Ok, my fault. I kept "localhost" as server location. I use 000webhost for mySQL. With this one, you have to specify a specific adress, not "localhost". I did make a test, but by writing "http://www."mySQLadress". Stupid mistake, this kind of adress don't need to have the "http://www" prefix. Instead of local host, I had to write exactly "mysql9.000webhost.com", the correct adress is given by 000webhost when you create the MySQL database.

 

Thanks again, Destron, now I have your online Gamemaker example which feed a database. I still have an error : the online gamemaker interface specify "either you name is in use or their was an error (etc)" but the important thing is : gamemaker file which can communicate with an online database, That's really great, thank you so much.

I feel I become a "level 2 newbie".

Ok, time to try to make some changes in the code.


  • 0

#13 tom713

tom713

    GMC Member

  • GMC Member
  • 19 posts

Posted 30 March 2014 - 10:36 PM

I spoted the reason for the error message explained in my previous post.

In the GM file, in the HTTP event of the ObjSubmit, Gamemaker collect the message from the Php file, with this line of code :

 

data = ds_map_find_value(async_load,"result");

 

this "data" is supposed to switch between two values : 0 if something goes wrong, and 1 if it's ok.

 

Rather than writing the error message if the value is different from 1, let's display on screen this "data"

http_return = data;   //"Either your user name is in use or there was an error creating your account.##Please try a different user name.##If you continue to get this error please contact an admin."

The "data" value gathered many information. 1 or 0 plus a message from the Php file.

 

To make the game maker file work, let's collect only the first caracter of the data message to only focus on 1 or 0. Plus, it seems that the value collected should be considered as a string rather than an integer.

 

 

data = ds_map_find_value(async_load,"result"); //Get the returned result and store it as a variable.
data2 = string_char_at(data, 0)
 
if data2 == "1" //If the script returned 1 then everything was ok
{
    game_restart(); // Do what we do if the registration is valid, in this case restarte the game.
}
else //If the login was wrong...
{
// Display error message for the user. 
    http_return = "Either your user name is in use or there was an error creating your account.##Please try a different user name.##If you continue to get this error please contact an admin."
}
 
In that case, the game restart as it should if the database receive the new entry.
 
There's probably something more clever to do in that kind of situation, but maybe , at my weak level, I can provide some help n_n

  • 0

#14 AcTiViSioN

AcTiViSioN

    GMC Member

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

Posted 18 June 2014 - 08:40 AM

I use 000webhost.com, properly introduce your login and password, but still get the message "Can not connect to server". What to do?


  • 0

#15 Destron

Destron

    GMC Member

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

Posted 19 June 2014 - 03:40 AM

I have had a lot of people complain about 000webhost so I am making ab account there to try it out and see whats going on there. I will update you when I have a more solid answer. In short its the host, but its such a popular host I will figure it out and come up with a work around. 


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users