How do I use AJAX for this Job

0 favourites
  • 1 posts
  • Hi there,

    I need to help a friend to connect my game with AJAX to get some states back. I've never worked with AJAX and he isn't familiar with Construct 2. Maybe some of the community can help us out.

    Information

    [quote:3t65jpsd]What we need to do at the start is go to a file on our server and do an AJAX call ( which I'm told is easy to do in Construct 2) for the function getState(). Then if our program returns a state, the game should use that reconstruct the state of the program our student left it at. Our program will know which student the state is for, all the game needs to do is load up the saved state. If it gets nothing in return then it starts a new game.

    The game needs to save the state of itself often, so disconnecting randomly doesn't cause lost of major progress. To do this the game just calls the function in the same file called setState(state). doing this the game should give all the variables that are needed to recreate the progress of the game to our program. Such as how many levels where competed and which what score, stars, etc.

    Lastly, the game should kick a player out after about 7 minutes minutes. On your end all we need is for the game to decide after about 7 minutes of play time to end the game. If the player is in a level, it should wait until they either complete the level or lose. When either one of these events happen the game should go to the same file and (after saving the state) call the function gameBreak(). Then our side will handle taking the student out of the game and back into the rest of our program. Also if a player wants to voluntarily leave the game there should be an exit button which executes setState(state) and gameBreak()

    So to recap in a simpler way:

    To do this:

    1) On start the game should go to our php file and do a simple AJAX call. It should call the function getState(). This should get all the variables from our system.

    2) The game should do the call setState(state) often so progress isn't lost. This should save all the variables on our system.

    3) The game should call gameBreak() to tell our program it is time to kick a player out. Our program will handle kicking them out.

    Summary

    "/student/game/getstate"

    "/student/game/setstate/(statestring without "/"s)" OR "student/game/setstate" where AJAX passes the state string as POST data with name "state"

    and /"student/game/gamebreak"

    These will return a raw string.

    Can anyone help with the AJAX Part?

    Thanks a lot!!

    We give away a free redeem Code for our Mobile Game UI PSD File for the helpers

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)