Jump to content


Photo

GM-PHP Communication


  • Please log in to reply
33 replies to this topic

#1 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 06 October 2011 - 04:59 AM

GM-PHP Communication

Using PHP as an extension in this manner (or any other language used with AJAX) has tremendous advantages. Database manipulation, date and time functions, and file compression procedures are just a few of the many systems that are now accessible through GM. I have authored an article outlining a procedure to communicate between GM and PHP using AJAX (JavaScript) as an auxiliary language. Small amounts of PHP, JavaScript and SQL are assumed, but not needed. This is in a sense an "upgrade" from my short tutorial about using GM to manipulate a MySQL database containing apples, just abstracted to a more general guide and is much more thorough.

Please notify me of any errors I missed while proofreading. Suggestions or general comments are always welcome.

Download the PDF here.

Posted Image

For the sake of completeness, I have created a simple example using the method outlined in my article to create a highscore table. View the live demo or download the editable .GMZ file.

Enjoy.
  • 3

#2 True Valhalla

True Valhalla

    ಠ_ಠ

  • GMC Member
  • 5277 posts
  • Version:Unknown

Posted 06 October 2011 - 09:21 AM

Excellent, can't wait to take a read through this. I hope there's some form of data validation this time! :)
  • 0

#3 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 06 October 2011 - 01:04 PM

Excellent, can't wait to take a read through this. I hope there's some form of data validation this time! :)

Not too much data validation this time, when when I find the time, I'm planning on writing a few more sections and this will be one of them. Another being a more detailed look at SQL statements.
  • 0

#4 True Valhalla

True Valhalla

    ಠ_ಠ

  • GMC Member
  • 5277 posts
  • Version:Unknown

Posted 06 October 2011 - 09:37 PM

Ah, I see. I figure it's good to have at least some basics there so people know the system is vulnerable :)
  • 0

#5 OMGCarlos

OMGCarlos

    GMC Member

  • GMC Member
  • 329 posts
  • Version:GM:HTML5

Posted 06 October 2011 - 10:57 PM

Awesome write up, probably one of the best documented articles for GM I've seen recently - felt like I was reading from a text book which is a good thing! Definitely saving this for reference later. The links at the end was an excellent touch, didn't know w3 schools had a php tutorial series. My only criticism is that you should probably have stressed a bit more the fact that there are security risks involved with using php like True Valhalla said. Otherwise awesome work!
  • 0

#6 pedrosorio

pedrosorio

    GMC Member

  • GMC Member
  • 971 posts

Posted 06 October 2011 - 11:15 PM

It's short but very well done. Consider also placing this on the tutorials section (probably with a [HTML5] tag in the topic name to allow it to be moved if they change the forum structure).
  • 0

#7 rukiskiller

rukiskiller

    GMC Member

  • GMC Member
  • 5 posts

Posted 07 October 2011 - 07:12 AM

That's just what i need. Thanks for the excellent work. In this way, GM can also work with database without any .dll files.

And a question, javascript can also communicate with database. why didn't you use javascript to do the work directly?
  • 0

#8 pedrosorio

pedrosorio

    GMC Member

  • GMC Member
  • 971 posts

Posted 07 October 2011 - 08:01 AM

And a question, javascript can also communicate with database. why didn't you use javascript to do the work directly?


How so? The only way I know for a client-side javascript to access the database is through a server-side language like PHP using AJAX, which is used in this tutorial.
  • 0

#9 tomasart

tomasart

    GMC Member

  • GMC Member
  • 263 posts

Posted 07 October 2011 - 08:43 AM

Thanks a lot, works very fine.
  • 0

#10 goresoft

goresoft

    GMC Member

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

Posted 07 October 2011 - 09:09 AM

good work!! You made an excellent pdf!

It seems a part of university degree thesys. :biggrin:

But i 've a problem with your gmz. When i open it nothing seems to load. No objects, no extensions, no backgrounds.

Please check it!
  • 0

#11 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 07 October 2011 - 10:55 AM

Even if it were possible to connect to a database directly, it would be silly as that means the username and password would be on the clients computer. Big security no no.
  • 0

#12 Destron

Destron

    GMC Member

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

Posted 08 October 2011 - 07:09 AM

That's just what i need. Thanks for the excellent work. In this way, GM can also work with database without any .dll files.

And a question, javascript can also communicate with database. why didn't you use javascript to do the work directly?


JavaScript cannot directly communicate with an SQL database. You have to use Ajax or PHP to connect to a db. Javascript is client side only.
  • 0

#13 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 11:56 AM

You just gotta love what php/javascript has to offer.

http://syntaxgames.com/game/

The link above is to an example of a level editor that uploads levels online for all to play. Very rushed and unfinished.
  • 1

#14 OMGCarlos

OMGCarlos

    GMC Member

  • GMC Member
  • 329 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 04:00 PM

Whao Schalk very nice example, that could be very useful if you work on it a bit more!
  • 0

#15 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 10:28 PM

Thanks for the feedback!

I'm hesitant about creating a section about security, because it won't easily be abstracted to the general procedure, i.e. it would have to be specific to what the PHP is doing. But I'll come up with some way-perhaps restructuring the document.

I'm also thinking about adding in a few, less formal sections with examples and whatnot.

Interesting implementation, Schalk.
  • 0

#16 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 10:46 PM

It might be nice to add something about caching. For example instead of doing /highscore.php you would do /highscore.php?rand=41209 so it doesn't retrieve the cached stuff
  • 0

#17 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 10:50 PM

Good idea. I was also thinking about including jQuery, which if I'm not mistaken, has a parameter to handle caching in the .ajax method.
  • 0

#18 OMGCarlos

OMGCarlos

    GMC Member

  • GMC Member
  • 329 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 10:56 PM

It does, and its as easy as using $(element).ajax();
  • 0

#19 cerberus150

cerberus150

    GMC Member

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

Posted 09 October 2011 - 04:08 AM

good work!! You made an excellent pdf!

It seems a part of university degree thesys. :biggrin:

But i 've a problem with your gmz. When i open it nothing seems to load. No objects, no extensions, no backgrounds.

Please check it!

Same here, it gives me nothing.
  • 0

#20 cotycrg

cotycrg

    GMC Member

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

Posted 09 October 2011 - 04:24 AM

You just gotta love what php/javascript has to offer.



The link above is to an example of a level editor that uploads levels online for all to play. Very rushed and unfinished.

Would you be as kind as to upload the source to that? (be sure to blank out any username's or passwords you have stored! ;) )
  • 0

#21 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 09 October 2011 - 06:37 PM


You just gotta love what php/javascript has to offer.



The link above is to an example of a level editor that uploads levels online for all to play. Very rushed and unfinished.

Would you be as kind as to upload the source to that? (be sure to blank out any username's or passwords you have stored! ;) )

I assume he just used text files stored on the server or a MySQL database. The program could write the level data into a text file with PHP and save it to a specific directory. To generate the list of levels, PHP would only have to iterate through that directory and return the list. It could also just write the level data into a SQL row entry, which I think would be much easier. Returning the list of levels would be as simple as SELECT * FROM levels LIMIT 0,10.
  • 0

#22 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 09 October 2011 - 11:00 PM

My code is too embarrassing to share sorry :P. But yeah I just had a ini file that had the names of all the levels then in the same directory there were the files 0.txt, 1.txt, 2.txt etc. Not very flexible at all.
  • 0

#23 Joe H

Joe H

    GMC Member

  • GMC Member
  • 352 posts
  • Version:Unknown

Posted 17 October 2011 - 04:45 PM

I cannot find the "import" option under the File menu. The help file says that it should be there, but I do no see it. Am I looking in the wrong place? Where is the import function for the .gmz file?

After referring to THIS THREAD I attempted to import the gmz file in the manner suggested. It still appears to be a blank file and no resources are imported. Any suggestions?

Edited by Joe H, 17 October 2011 - 05:05 PM.

  • 0

#24 Joe H

Joe H

    GMC Member

  • GMC Member
  • 352 posts
  • Version:Unknown

Posted 19 October 2011 - 06:33 AM

Anyone have any information on this?
  • 0

#25 Zeond Games

Zeond Games

    Tactical Recon Developer

  • GMC Member
  • 115 posts
  • Version:GM8

Posted 19 October 2011 - 01:41 PM

You're amazing....
  • 0

#26 Psalms23

Psalms23

    GMC Member

  • New Member
  • 163 posts

Posted 05 November 2011 - 03:23 AM

How to open .gmz?
  • 0

#27 123tomek

123tomek

    GMC Member

  • New Member
  • 12 posts

Posted 23 November 2011 - 10:11 AM

How to open .gmz?



There is description.
  • 0

#28 azcodon

azcodon

    GMC Member

  • GMC Member
  • 198 posts
  • Version:Unknown

Posted 24 November 2011 - 02:24 AM


How to open .gmz?



There is description.

**** **** ****
gm html5 can not read data of function as we call function
eg.
//in javasript
function sum(a,b)
{ return a+b; }
//in gm
add extension with function sum
c=sum(2,3) <-------unknown **** **** ****
  • 0

#29 Psalms23

Psalms23

    GMC Member

  • New Member
  • 163 posts

Posted 24 November 2011 - 06:49 PM

Nice.. Could this be used to read the time, so the game knows what time it is in real life, and then do checks on the time and execute events.

For example, say I want an object to appear in the room at 11.00am new york time, could I somehow read that off a site like this:http://www.timeanddate.com/worldclock/city.html?n=179

and then do checks on the time?
  • 0

#30 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 26 November 2011 - 08:50 PM

Yes, PHP can easily echo the time and date in regards to a particular time zone. In fact, you can do it with just JavaScript too.

About the editable: I probably exported it wrong. I'll eventually get a working version up.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users