Ajax request to variables

0 favourites
  • 9 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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 <img src="smileys/smiley19.gif" border="0" align="middle" />

    sorry for my bad english.

  • 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.

  • 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.

  • 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 <img src="smileys/smiley5.gif" border="0" align="middle" />

  • 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 methods

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Use the system expressions like tokenat.

    This way you can break down whatever string is returned in ajax.lastdata into several values.

  • Thanks for pointing that one out, Kaytric. That way easier than the XML setup I'm using for one of my projects.

  • 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: docs.google.com/file/d/0BxLVD9TlXa5QTjhpRWM3RmxEQ1U/edit

    .capx: dakation.altervista.org/GW2/GW2.capx

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