Read/Write Variable Using AJAX

0 favourites
  • 3 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Firstly, I've read the (incredibly helpful) AJAX tutorials and have poured over Izes' many helpful examples. The problem I'm having is mostly to due with my inexperience with PHP (and my interminably thick skull).

    Before I begin, some setup: My intention is to create a game that presents an obstacle to a player, first calling to a server-side file using AJAX that checks a variable's number stored in the file--lets say the value is "0." Just one character, 0. If the value is 0, the obstacle remains.

    The player presses "X," which prompts C2 to call using AJAX, writing and replacing the old character found in the server-side file (0) with a new character: 1. Binary stuff. Now, once the call is made to read the file in future, the callback is "1," as opposed to the "0." If the value is 1, the obstacle disappears! Wunderbar!

    Is there any kind coding wizard that can help me? Or perhaps someone helpful enough to point me to some resources that they feel might help me out the most? Again, I've read the tutorials--is there something I'm missing? Thanks, guys.

  • You need a PHP script/function that will look into a file and return the value. (That's readscores.php in Ize's example)

    The corresponding AJAX call points to the script and you use AJAX.getlastdata to know the value that is stored on your server side.

    Then you need another script/function to which you pass a parameter on call and that will store said parameter as value of the stored variable. (That's post.php in Ize's example).

    The corresponding AJAX call points to the URL of the script with your parameter added to it.

    What you want pretty much lies already in Ize's example.

    For the PHP itself, it is out of the scope of C2.

    It is a "classic" coding language and you need to learn its basics to be able to modify the scripts to your need.

    It's not overly complicated, but it takes time to get used to.

    Open the .php files in a notepad (you can use a specific notepad like notepad++ or devphp to profit from syntax highlight which helps getting a better understanding of the code once used to it).

    The lines that starts with // are comments. They explain the logic of the following code.

    To learn PHP a good place to start is the w3school. You can also go directly to the official manual of PHP (translated in many languages) and learn directly from the source.

    This is all very technical but PHP as been around for quite a long time and I'm pretty sure you can google something like "PHP for dummies" (in reference to the book that you might also buy. It has a good reputation of popularization of such technical domains).

    If you're low on budget you can always keep googling until you find a PHP beginner tutorial (up to date by all means) that suits you.

    You wanted ressources, here they are.

    It is possible to propose some key in hand solution/PHP framework that would be usable "easily".

    The drawback to this would be the limit of customization applyable to the framework and the time it would require to get built. Another concern could be security issues and the need for a regular maintaining of said framework.

    In the end it is a safer bet for the users (especially the younger ones) to learn directly PHP and be able to write their own scripts fully adapted to their needs.

    Moreover such knowledge of a coding language IS profitable in C2 since it helps getting used to arrays and loops and other common expressions/functions/designs.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Love 'yah, Kyatric! Thanks for the pointers--I really needed a guiding hand with all of this.

    EDIT: And I love your signature ;)

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