GameSalad

Sending and Receiving data using your own SQL Server - PHP file and TestProject included

jonmulcahyjonmulcahy Posts: 10,366Member, Sous Chef, PRO
edited January 2014 in Working with GS (Mac)
This guide assumes you are using a Mac. I did all testing on Mavericks.

Step 1: Download and install MAMP (http://www.mamp.info/en/index.html)

Step 2: Configure MAMP
Browse to Applications -> MAMP and click on MAMP. In the MAMP window click on Preferences and click on the Start/Stop tab. Make sure both Start and Stop are checked and uncheck the check for pro flag. The open at start is up to you. Leave the ports page alone unless you want to configure that yourself. PHP should be running 5.5.3, 5.2.17 seems to have problems with the JSON. Apache, leave alone. Hit OK to close the preferences tab.

At this point start your servers if they are not already green.

Step 3: Disable Caching
PHP 5.5 has some caching enabled which really caused some pain in testing. I would make a change and it would take awhile before it was enabled. You'll need to browse to /Applications/MAMP/bin/php/php5.5.3/conf/php.ini and comment out the OPcache section. It should be at the bottom. You want to put a ; in front of every line in that section.

Step 4: Create and Configure MySQL Databases
Browse to http://localhost:8888/MAMP/ and click on the phpMyAdmin link in the top bar. This will bring you to phpMyAdmin, a web management area for MySQL. It's very powerful, but since we are running MAMP, if you break something you can just reinstall. This is all based on the test project, but if you are using your own data, you want to make sure the tables match what you have in GS.

To start, click on the Databases tab. In the text box type in a tame and hit create. I'm using asyncTest.

image

After it's created click on the database in the list below. This will allow you to create a table. You can create as many as you want, but for this test we only need one. Give it 3 columns and hit GO. I called mine testData.

image

Now we have to create the columns. the names should match what you have in GS for ease of use, but it doesn't have to. The type needs to match exactly. I'm dealing with two columns of text and one integer. Hit save when you are complete

image

We are now done with the MySQL Configuration. Let's move over to PHP.

Step 5: Configure PHP
We are going to be copying the template PHP file into /Applications/MAMP/bin/mamp/. I have it called asyncTest.php, but you can call it anything you want, even index.php. Before you go any further, we need to talk about security. This script is wide open, the default MySQL username and password are written in plain text and stored right in the file. When you push this to production you will NEED to secure this up. There are many methods of doing this, so I'll leave it up to you. I will be attaching the script in a separate post below.

Step 6: Configure the Test app
I will be posting my test app in a separate post as well, but at this point we need to configure it. If you are testing this locally and didn't deviate anything from above, you don't have to do anything. If you are testing remotely you will have to alter the URL attributes. I have two URL attributes in the app, a sendURL and receiveURL. My script handles both POST and GET so they both point to the same script.

At this point, the app should be fully functioning. Pretty simple huh? When you execute the script you must first click on the CONNECT button. This initializes the network features, but i hear in the future this will not be required. After that, hit the send button. When you see the send status turn green, your data has reached the server. At this point if you browse to the location of asyncText.php you will see a json.txt file. This is the output of the network call. You will need this later when you customize this for your data.

If you want to insert some records into the table manually do it now. Click on the database name in the left column, then again on the table name. Click on the Insert tab and input some values and hit GO. Do this 2 or 3 times.

image

Now go back and hit GET in the app, you should see the next three values populate in the game.

That's it! I will be posting the php script and test app next, they deserve their own post.
«13456715

Comments

  • marplumarplu Posts: 412Member, PRO
    Awesome! Thanks a lot for this tutorial, should be a sticky thread :)
  • StormyStudioStormyStudio United KingdomPosts: 3,985Member
    Outstanding...
  • jonmulcahyjonmulcahy Posts: 10,366Member, Sous Chef, PRO
  • EireStudiosEireStudios Posts: 451Member, BASIC
    Awesome work Jon, thanks for sharing all your hard work! :D
  • GSdustinGSdustin Posts: 16Member, PRO, Chef Emeritus
    WOW! This is really stellar work. Keep it up! :)
  • tatiangtatiang Posts: 10,849Member, Sous Chef, PRO, Senior Sous-Chef
    @jonmulcahy Impressive work and dedication to this feature! It looks a little overwhelming but I'm going to hunker down and see if I can get this set up with your clear directions above.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • jonmulcahyjonmulcahy Posts: 10,366Member, Sous Chef, PRO
    stevej said:


    FYI, the Playstogether requirement for the URL commands WILL go away. I will also be adding a new network option "my own server" (or words to that effect) which will only enable the URL commands.

    awesome, awesome awesome!
    this feature is the most exciting one to come to GS since universal builds!
  • jonmulcahyjonmulcahy Posts: 10,366Member, Sous Chef, PRO
    GSdustin said:

    WOW! This is really stellar work. Keep it up! :)

    thanks! got to bust out some dormant PHP knowledge :)

  • RiffelRiffel Posts: 1,272Member
    Great! I follow the steps, but when I pressed play in the asynTest.gameproject nothing happens! I have to place the .gameproject at the mamp/php folder? server data is a hard thing to me. 8-X
  • jonmulcahyjonmulcahy Posts: 10,366Member, Sous Chef, PRO
    game project is seperate.

    check under MAMP\Logs to see if anything is showing up

    Make sure the URL attribute is hitting a valid page
  • uptimistikuptimistik Trinidad and TobagoPosts: 3,593Member, Sous Chef, PRO
    @jonmulcahy Hats off to you good sir, you deserve a medal of some sort...splendid work!

    New Templates Daily At The Official GameSalad Marketplace GSHelper.com

  • jonmulcahyjonmulcahy Posts: 10,366Member, Sous Chef, PRO

    @jonmulcahy Hats off to you good sir, you deserve a medal of some sort...splendid work!

    thanks, using a custom server is something I've been looking forward to for a long time. those two little behaviors are so incredibly powerful it's crazy. There is so much that could be done with the right back end.
  • RiffelRiffel Posts: 1,272Member

    game project is seperate.

    check under MAMP\Logs to see if anything is showing up

    Make sure the URL attribute is hitting a valid page

    http://localhost:8888/MAMP/asyncTest.php
    returns "cannot select DB"
  • jonmulcahyjonmulcahy Posts: 10,366Member, Sous Chef, PRO
    I'm guessing your DB name in MySQL and what you have in the php.ini file don't match.

    that DB name occurs a few times throughout the file, make sure you change them all. In the PHP file I uploaded i had the db name set to GSTest instead of asyncTest.
  • tatiangtatiang Posts: 10,849Member, Sous Chef, PRO, Senior Sous-Chef
    @Riffel This happened to me before I replaced "GSTest" with "asyncTest" in several places in the asyncTest.php file.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Posts: 10,849Member, Sous Chef, PRO, Senior Sous-Chef
    Yee haw! I was able to get the SEND button to work but when I click GET after adding table data in MySQL it gives me a callback of 1 but nothing changes in the scene so I don't think the table data has changed.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Posts: 10,849Member, Sous Chef, PRO, Senior Sous-Chef
    Should I see the existing table data (which appears in json.txt) in the MySQL table view?

    image

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • StormyStudioStormyStudio United KingdomPosts: 3,985Member
    edited January 2014
    Just hit the same problem as Riffel... I'd also missed the step of updating the php.ini file...

    I can now successfully send the file to the correct folder, and preview the json.txt file. However the testData table in the asyncTest database is'nt being populated with the table info. I can manually go in and add info in phpMyAdmin, but this does'nt update in the JSON.txt file either.

    I've used the same names as you. Also when I press 'Get' nothing new happens, but then there's nothing new in the json.txt file so I'm not expecting it to... (I did try manually typing in some new variables in the JSON.txt file but probably did that wrong anyway).

    I'll go through the process again and see what I've missed... I also need to read through your code so I soak up a little bit of knowledge.

    EDIT ... This is now fixed... see my next post down.
  • RiffelRiffel Posts: 1,272Member
    fixed. but when I try connect the top button is set to red and NetworkConnectStatus:-1
  • StormyStudioStormyStudio United KingdomPosts: 3,985Member
    edited January 2014
    SUCCESS.

    When changing the gsTest text in the php file from Jon Mulcahy

    Change the first one to 'asyncTest' as this is asking for the name of the database.

    From then on it knows which data base your looking at, and just needs the table name.

    So the other two instances of gsTest need changing to dataTest (or what ever your table is called inside the the database.

    I've earnt myself a tea. :-)

    (hold that tea... I seem to be losing the 2 columns info (playerName) when getting the table back... but the id and stats come through fine... I must have made a typo in the code.)...

    Oh I'm allowed the tea again. When going back through the process I'd named the table row 'playerNAME' not 'playerName' so the php code did'nt see it.

    All fixed and working beautifully.

    @jonmulcahy
    When I send the table from GameSalad it adds more rows to the table rather than replaces the data, is that working the same your end?... thanks Jon
  • StormyStudioStormyStudio United KingdomPosts: 3,985Member
    @Riffel I had the same problem.

    I went into SEND button actor, and changed the test info for logging in, into something else random. No reason for it, but it worked successfully after adding some fresh login info.

  • jonmulcahyjonmulcahy Posts: 10,366Member, Sous Chef, PRO
    wow lots of progress :)

    @tatiang, that json file is only what your app is sending, it doesn't update further. if you put this line at 146 you can get an output of the GET command

    file_put_contents('updatedjson.txt',$returnedJson);

    @stormystudio
    yes, this code just appends the new data. It would be pretty easy to update the MYSQL code to update it, but for now i just append.

    probably would have been better of me to make sure the tutorial and PHP file matched, but oh well :)
  • StormyStudioStormyStudio United KingdomPosts: 3,985Member

    wow lots of progress :)
    probably would have been better of me to make sure the tutorial and PHP file matched, but oh well :)

    Don't be silly... I'd of never earnt my tea if you'd done that.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,881Member
    Awesome work. I have to download and copy all this info for future knowledge. Too busy with everything else right now.
  • tatiangtatiang Posts: 10,849Member, Sous Chef, PRO, Senior Sous-Chef

    When changing the gsTest text in the php file from Jon Mulcahy

    Change the first one to 'asyncTest' as this is asking for the name of the database.

    From then on it knows which data base your looking at, and just needs the table name.

    So the other two instances of gsTest need changing to dataTest (or what ever your table is called inside the the database.

    This was my problem. Aha! Thank you @StormyStudio!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

«13456715
Sign In or Register to comment.