How do I pull variables from a php page?

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply Page  123 7>
Author
700 Rep
Post Options Post Options   Quote b781rev Quote  Post ReplyReply Direct Link To This Post Topic: How do I pull variables from a php page?
    Posted: 04 Oct 2011 at 10:15am
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.
Back to Top
6,861 Rep
Post Options Post Options   Quote Wastrel Quote  Post ReplyReply Direct Link To This Post Posted: 04 Oct 2011 at 1:38pm
Back to Top
700 Rep
Post Options Post Options   Quote b781rev Quote  Post ReplyReply Direct Link To This Post Posted: 04 Oct 2011 at 9:41pm
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.

Edited by b781rev - 04 Oct 2011 at 9:44pm
Back to Top
2,037 Rep
Post Options Post Options   Quote Mehtab Quote  Post ReplyReply Direct Link To This Post Posted: 04 Oct 2011 at 9:48pm
I don't think you can. Maybe I am wrong.
Back to Top
700 Rep
Post Options Post Options   Quote b781rev Quote  Post ReplyReply Direct Link To This Post Posted: 04 Oct 2011 at 9:53pm
Then how would I go about doing a saved data feature without using the sessions or local storage?
Back to Top

Moderator
29,626 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 04 Oct 2011 at 10:58pm
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.
Back to Top
700 Rep
Post Options Post Options   Quote b781rev Quote  Post ReplyReply Direct Link To This Post Posted: 04 Oct 2011 at 11:17pm
I know, but how do you retrieve it from constructor 2 itself and use the variables in the game?
Back to Top

Moderator
29,626 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 04 Oct 2011 at 11:21pm
With the expression "LastData" from the ajax object.

Quote 2. 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

Edited by Kyatric - 04 Oct 2011 at 11:22pm
Back to Top
700 Rep
Post Options Post Options   Quote b781rev Quote  Post ReplyReply Direct Link To This Post Posted: 04 Oct 2011 at 11:31pm
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.

Edited by b781rev - 04 Oct 2011 at 11:34pm
Back to Top

Moderator
29,626 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 05 Oct 2011 at 12:11am
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.
Back to Top
 Post Reply Post Reply Page  123 7>

Forum Jump Forum Permissions View Drop Down