How do I initialize the contents of my array?

0 favourites
  • 3 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I'm making a platformer game with a procedurally-generated world. The game makes chunks of map by spawning and giving properties to several sprites at a time based on an array. In other words, each x-value is a different sprite with all its properties, and all the x-values for one z-value are a chunk of map. Initializing the array is what gives me trouble. I know I can use JSON strings to load an array, but how do I make such a string? Is there a way to embed this string in my final game? Otherwise, I'm stuck writing to hundreds of array elements separately in one simply gigantic event. I'd appreciate any help you can give.

  • Well... If your world is procedurally generated, your procedural algorithm should probably populate your array as you go.

    If you want to load an array you create manually, you can create it in your spreadsheet program of choice, save as .csv, import that with the AJAX object, then use tokenat to break it up and load it into your array.

    If you're looking for an algorithm to procedurally generate terrain... I'm not much help there but I'm sure there are a ton of tutorials and examples online.

    JSON strings are created from already-populated arrays - you can use Array.asJson to get the contents of the array all in one string, in JSON format. You can then save this string and load it back into an array later.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks! This should be just what I need. The reason I need the array is that I design several small sections of map and store them in array, then the game randomly chains them together by duplicating each section from the array's instructions.

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