How do I pull variables from a php page?

0 favourites
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi,

    I'm wondering how I can pull variables I load from a mysql database in a php page to my game? I can send the ajax request to save data but do not know how how to retrieve that data to load certain things in my project. Any help would be greatly appreciated. Thanks.

  • Did you take a look at this tutorial?

    http://www.scirra.com/tutorials/61/ajax-example-with-construct-2

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yes I did, but it doesn't explain exactly how to retrieve variables from a php page and use them in your game. It explains how to call a page and load that page. I can save game information into my database with that method, but I want to pull data from my database by the users being logged in, and if data for that game has been saved it can be loaded into the game for that user from the data pulled from the database in which I put into variables. Does that make any sense at all. Just got off work and a bit tired. Maybe I'm missing something, I don't know.

    For example I have:

    $var1="value";

    in my php page.

    I want to get the value of $var1 into my game using the AJAX method.

    I'm guessing I might just be missing something and just can't see clearly right now so any help would be greatly appreciated. Thanks.

  • I don't think you can. Maybe I am wrong.

  • Then how would I go about doing a saved data feature without using the sessions or local storage?

  • You can retrieve datas from PHP, but in that case, it needs code in the PHP page itself that will send back said-variable.

    This is not the purpose of this forum though to deal about PHP.

    Try to search the keywords "webservice", "xmlrpc" and "PHP" on google. This is some of the way PHP can send back infos to an ajax call.

  • I know, but how do you retrieve it from constructor 2 itself and use the variables in the game?

  • With the expression "LastData" from the ajax object.

    . When the call to the page is done, the information collected is stuffed into the AJAX.LastData object where we can then consume it in our game.

    First page of the tutorial.

    You can assign a global variable to the value of Ajax.LastData.

    Action

    System -> Set global variable value

    Name of the var; value of the var : AJAX.LastData

  • So basically I have to make a call for everything I want to load for example:

    php page - level: 5

    and it would be like var AJAX.level

    ... it will retrieve 5 and I can load the level from that if I put it into a global variable?

    Sorry, just trying to get my head around it. I know how AJAX and php work but for some reason I just can't get this through my head. This is the only thing I'm having a problem with in this program.

  • If your PHP variable value is 5, then the value of AJAX.LastData will be 5.

    So you create a variable Level in Construct and assign it the value of AJAX.LastData (like I showed in my previous post)

    If you make another call, the value of your PHP variable will be returned to C2 still as the value of AJAX.LastData, so you can assign another variable to the value of AJAX.LastData.

  • Ok, I think I have it. I will try it out in a little bit. Thanks for your help and sorry for being a pain. I won't be this troublesome in the future.

  • No problem, you weren't troublesome.

    It just took a few posts to figure out what you were asking for and anyway I think this will be profitable in the future because I bet other members will ask themselves the same thing you did.

    Having the answer in the forum is never a bad thing <img src="smileys/smiley4.gif" border="0" align="middle" />

  • I have the same ponderings. Trying to wrap my head around this Ajax stuff.

  • hahahaha. Same for me. It's tricky.

  • I'm going to be doing some work on the whole AJAX thing within the next couple days. I think I have a pretty good grip on it, but it will take some time to get it figured out. I will post whatever I figure out. I have only been using this program for two days so I'm new.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)