Static Array in Project?

0 favourites
  • 7 posts
From the Asset Store
With this template you can create your own archer game and customize it however you want.
  • Hi, I've tried to search and read on this, and while some things suggest it possible I could not figure out exactly how.

    I would like to save an array of dimensions 30,10,10 in a way to be able to export the project with the saved data available to be read in when it runs on the player's computer.

    Is there a tutorial that shows this or an easy explanation?

    Thanks

  • You can use the array download action to save the array to a file and then add it as a project file. See this:

    https://www.scirra.com/tutorials/328/using-project-files-in-construct-2

  • hmmm, so it does look like it can be done, though I'm still not seeing any clear examples. It seems they suggest at first to store files on a server somewhere on the net and then load them via URL's. Not exactly what I want. Any one able to provide short example or link to tutorial that shows how to actually save an array using this 'dictionary' or 'json' or whatever it is, then how to find that file to put in with the exports? It isn't as simple as 'dictionary - set array to array.tojson' and then when file is in the project that was DL'd you start with 'dictionary - load array.json'? And where do I find the actual file saved as 'array.json'?

    The Construct2 manual is pretty good, but when non basic techniques are mentioned, they don't really elaborate on how to use them.

  • When you have the array filled you can use the array Download action to save it to a file:

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/arrayToProjectFile01.PNG" border="0">

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/arrayToProjectFile01a.PNG" border="0">

    When you run that action it will pop up the save file dialog or just save the file directly to your download folder depending on how you have your browser set up:

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/arrayToProjectFile02.PNG" border="0">

    The file looks like this. It's the array in JSON format (I call it 'level.json' and have notepad set to open .json files. You can call it 'level.txt' or anything really.):

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/arrayToProjectFile02a.PNG" border="0">

    You could also create this file by hand or generate it with code.

    Now you can add that file to your project (When you want to change the level just open this file from within C2 and edit it instead of deleting and importing it again.):

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/arrayToProjectFile03.PNG" border="0">

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/arrayToProjectFile04.PNG" border="0">

    Now you need to add the AJAX plugin to the project and request the file:

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/arrayToProjectFile05.PNG" border="0">

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/arrayToProjectFile06.PNG" border="0">

    When the request has completed, the value AJAX.LastData will hold the contents of the file. Use the array 'Load' action to load it into the array.

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/arrayToProjectFile06a.PNG" border="0">

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/arrayToProjectFile07.PNG" border="0">

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/arrayToProjectFile08.PNG" border="0">

    Example: levelEditorExample.capx (r139)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ramones

    Thank you very much for that. One question, will that array save file get exported with my project so that when it runs elsewhere the program can load it just the same?

  • Yep any files added as project files are exported with the project.

  • Yep any files added as project files are exported with the project.

    Awesome! I thank you for helping out!

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