How do I pull variables from a php page? Forum Home > Construct 2 General > How do I....? |
Post Reply
|
Page 123 7> |
| Author | |
Post Options
Quote Reply
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. |
|
![]() |
|
Post Options
Quote Reply
Posted: 04 Oct 2011 at 1:38pm |
|
|
Did you take a look at this tutorial?
http://www.scirra.com/tutorials/61/ajax-example-with-construct-2 |
|
![]() |
|
Post Options
Quote Reply
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 |
|
![]() |
|
Post Options
Quote Reply
Posted: 04 Oct 2011 at 9:48pm |
|
|
I don't think you can. Maybe I am wrong.
|
|
![]() |
|
Post Options
Quote Reply
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?
|
|
![]() |
|
Post Options
Quote Reply
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. |
|
![]() |
|
Post Options
Quote Reply
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?
|
|
![]() |
|
Post Options
Quote Reply
Posted: 04 Oct 2011 at 11:21pm |
|
|
With the expression "LastData" from the ajax object.
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 |
|
![]() |
|
Post Options
Quote Reply
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 |
|
![]() |
|
Post Options
Quote Reply
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. |
|
![]() |
|
Post Reply
|
Page 123 7> |
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |