Fill Array and Save as JSON

0 favourites
  • 6 posts
From the Asset Store
An educational game for Fill in the Blanks. An easy to use template for developers to build larger games
  • I've been reading the tutorials on arrays, and have looked at the FAQ about arrays, but I still seem to be missing how they work in Construct 2. I am trying to save a list of animation frames to an array and download it via JSON but have had no success.

    In this example, I am painting terrain (hold SPACE and left click on the terrain you want to paint in the menu, then just left click on the map) and I want to save it with the "`" key, and download it by pressing TAB. This is just a test for something later, but I can't seem to get the saving part right. I'm not sure how Construct iterates over an array.

    Example capx: Capx

    Any help will be greatly appreciated.

  • Watch this tutorial I made last month, this should give you some ideas.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have looked at your tutorial before posting, but as you state at the beginning of your tutorial, it is not for absolute beginners. It seems that when it comes to arrays in C2, I am an absolute beginner.

    I know in other languages, I would:


    For X in Width:

    For Y in Height:

    Array[X,Y] = Tile.Frame

    //End Loop

    But I cannot seem to figure out how to do this properly in C2.

    My array is always full of 0's.

  • I've been having the same problem. Arrays are so much more straight forward in programming languages compared to c2. I use dictionaries instead

  • Can you give me an example that uses dictionaries instead?

  • After some Trial and error, I have been able to get a dictionary to store the data correctly.

    Keyboard: On key pressed:

    -+System: For each TerrainTile: Dictionary: Add Key"Tile"&TerrainTile.UID with value TerrainTile.AnimationFrame

    I tried this same method with Arrays with no success. I'm not sure why it won't work, but I guess I'll move on to using dictionaries barring one more thing.

    I am able to download the data.json file, but how do I go about loading it? I've looked at the project files tutorial, but I don't see an example on how to load the saved dictionary. Can someone point me on how to load a .json file to a dictionary with a project file?

    I'm not interested in keeping the file in webstorage.

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