How do I pull variables from a php page?

Get help using Construct 2

Post » Tue Oct 04, 2011 10:15 am

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.
B
3
G
1
Posts: 50
Reputation: 725

Post » Tue Oct 04, 2011 1:38 pm

Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Tue Oct 04, 2011 9:41 pm

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. b781rev2011-10-04 21:44:49
B
3
G
1
Posts: 50
Reputation: 725

Post » Tue Oct 04, 2011 9:48 pm

I don't think you can. Maybe I am wrong.
B
12
S
5
G
5
Posts: 80
Reputation: 3,572

Post » Tue Oct 04, 2011 9:53 pm

Then how would I go about doing a saved data feature without using the sessions or local storage?
B
3
G
1
Posts: 50
Reputation: 725

Post » Tue Oct 04, 2011 10:58 pm

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.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Tue Oct 04, 2011 11:17 pm

I know, but how do you retrieve it from constructor 2 itself and use the variables in the game?
B
3
G
1
Posts: 50
Reputation: 725

Post » Tue Oct 04, 2011 11:21 pm

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.[/quote]
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.LastDataKyatric2011-10-04 23:22:03
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Tue Oct 04, 2011 11:31 pm

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. b781rev2011-10-04 23:34:36
B
3
G
1
Posts: 50
Reputation: 725

Post » Wed Oct 05, 2011 12:11 am

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.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Next

Return to How do I....?

Who is online

Users browsing this forum: R0J0hound and 27 guests