How do I initialize the contents of my array?

Get help using Construct 2

Post » Thu Feb 18, 2016 4:06 am

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.
Eh, Steve!
B
113
S
54
G
13
Posts: 112
Reputation: 16,095

Post » Thu Feb 18, 2016 4:58 am

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.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Thu Feb 18, 2016 5:11 am

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.
Eh, Steve!
B
113
S
54
G
13
Posts: 112
Reputation: 16,095


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests