Ajax request to variables

Get help using Construct 2

Post » Thu Jan 31, 2013 3:30 pm

Hi i successfull use the "Post to URL" to sent a game variable to a remote PHP file and saved to mysql table.

Now i want to get data from a remote PHP script and use this values for the game variables such us Player.Health, Player.ammo etc...

But i dont Know how

sorry for my bad english.
B
3
Posts: 3
Reputation: 281

Post » Thu Jan 31, 2013 4:00 pm

@luca

mysql select query

This is how i'm doing it. You just echo the result that is returned to your game in ajax.lastdata.
B
17
S
9
G
7
Posts: 249
Reputation: 6,922

Post » Thu Jan 31, 2013 4:16 pm

tnx for the answer i already know this, but i dont know how to put them in the variable i do the following step in C2(it's a little pseudocode)

Condition -> On start of layout
Action->AJAX request "http://www.domain.com/test.php" tag GetHealth

COndition-> AJAX "GetHealth" complete
Action-> Player set Health to int(AJAX.LastData)

IN test.php i only have this line of code

echo 200;
i only want to put this 200 on Health variable.
B
3
Posts: 3
Reputation: 281

Post » Thu Jan 31, 2013 4:20 pm

Set variable.health to lastAjaxData. I dont know if is this what you want.
This should work

EDIT.ok this is already what you have cesisco2013-01-31 16:28:10
B
33
S
11
G
9
Posts: 381
Reputation: 10,153

Post » Thu Jan 31, 2013 4:32 pm

I solved my code is right, but the ajax request does not work in localhost(but work if you send data to remote php script), i uploaded my project in a webserver and now the health variable is set from the php script.

EDIT: there is an easy way for sending and retrieve multiple data Because AJAX.LastDara Contain only one value and if i want data Like querystring data1=value1&data2=value2? or other serialize methodsLuca2013-01-31 16:41:26
B
3
Posts: 3
Reputation: 281

Post » Thu Jan 31, 2013 7:51 pm

Easy way? The answer to that depends on your knowledge of XML. You can make your php return an xml file rather than just echo a single variable, then use Construct's XML Plugin to parse the data and put it into your variables.
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Thu Jan 31, 2013 8:05 pm

Use the system expressions like tokenat.
This way you can break down whatever string is returned in ajax.lastdata into several values.
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,998
Reputation: 57,791

Post » Thu Jan 31, 2013 8:21 pm

Thanks for pointing that one out, Kaytric. That way easier than the XML setup I'm using for one of my projects.
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Thu Jun 20, 2013 9:44 am

I've a similar problem:
I recieve a data from Ajax (i test it with an alert and the data is "ok") but the compare (ajax.lastdsta = "ok") fail why?

(In the image there is the eventsheet with the problem)

image: https://docs.google.com/file/d/0BxLVD9TlXa5QTjhpRWM3RmxEQ1U/edit
.capx: http://dakation.altervista.org/GW2/GW2.capx
B
8
S
1
Posts: 5
Reputation: 252


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 33 guests