Built in examples: AJAX

0 favourites
  • 9 posts
From the Asset Store
Unlock platyers earning coins, and save it with Localstorage
  • Would love to see some simple built in examples/samples of AJAX in action...

    WebStorage might be nice as well...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Probably a good idea. :)

    Meanwhile, here is a screenshot from one of my projects. It loads array of data from a simple text file(json format):

    <img src="https://dl.dropboxusercontent.com/u/19921470/ajax.PNG" border="0" />

    Here are contents of the text file:

    {

    "c2array":true,

    "size":[5,7,1],

    "data":[ [["Bob the Builder"],["He builds things."],[1],[2],[10],[100]],

    [

    ["Ben the Builder"],["He builds things."],[1],[2],[10],[100]], [

    ["Bill the Builder"],["He builds things."],[1],[2],[10],[100]]

    ]}

  • Well this is awesome... really, incredibly helpful and explains a ton! I can read about it in the manual all day but until I see it in action like this I am so lost...

    This helps make the concept of "tags" make a lot more sense.

    I can see how this is going to save me tons of time on my first-run data load...

    Where would the .txt files for this be kept?

    Is there a way to update the .txt files? That's really the big killer for me.

    My app basically collects names from user input and creates an array to hold the names. Being able to export this into any kind of file that I can access with 3rd party software (text editor, Excel, etc) is my goal. I have to ensure that the list of names in the array is stored in a stable data location that I can access if something goes wrong...

    Thanks again for the help this is huge!

  • "Where would the .txt files for this be kept?" -- what I meant by this was where do I place the .txt files to be called? Same folder as the app (e.g. same folder as the .exe for a Windows export)?

  • First, you'll need to save your project in project format instead of a single .capx file. This can be done from the menu of construct 2, 'Save as project'.

    After that you can create your text file and import it to construct 2 by right clicking projects 'File' folder and selecting 'Import file'.

    <img src="https://dl.dropboxusercontent.com/u/19921470/projectFiles.PNG" border="0" />

    Now the file will appear in your project folders 'File' folder.

    <img src="https://dl.dropboxusercontent.com/u/19921470/projectFolders.PNG" border="0" />

    You can now use external editors to modify those files and changes will be reflected in the game every time you load the file :)

  • That is awesome... my project was incredibly complex to accomplish basically the same thing...

    Can the game make changes/updates to the files? Or just load them?

    This project has a huge list of names... I can always create the list in a comma-delimited format and paste it into a global text variable and split it out into an array on load... I'd still rather use what you've shown me and load the .txt file so I can update it from outside the game then just reload the file as needed.

    The list of names can be edited by certain users and my hope is to be able to capture those changes as they are made... ideally to a file I can access. Cleaning up array.Asjson is preferable to nothing!

    Thanks for all the help! Between you and rexrainbow I think I'm finally getting a grasp on some AJAX basics. Thank even more for utilizing the "tags" ... that part really confused me as to how you would use it, this is a lot more efficient and slick compared to the nightmare I wrote lol!

  • The game can't change the files in the project, but you can upload a JSON file online (like Dropbox) and use AJAX request URL to obtain the required data. It makes the game more flexible and you can change levels remotely without uploading a new version. For capturing data, I recommend using php and mysql. See this tutorial for more info:

    https://www.scirra.com/tutorials/585/how-to-make-an-ingame-costume-made-level-editor

  • Thanks for the push in what's probably going to be the right direction...

    Its going to be interesting... I am on a very closed system for where this project will run. No interwebs, probably not even a local network... and I know nothing about PHP and only a tiny bit of mysql... I usually run huge projection systems, this is a little out of my skill set but you guys are the best at helping :)

  • vee41

    I've been trying to figure this out for days... all the posts just say "Add the file using AJAX, it's easy".

    I've been pasting my file into the Files directory, but it never showed up in the Request Project File list.

    Your post is the only one that explained that I needed to Import it into the Project first. Thanks so much!! (still useful even 6 months after your post)

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