# How do I create level data? (Arrays question)

Get help using Construct 2

### » Wed Sep 17, 2014 2:14 am

Hi there, all!

First off, let me preface that while I do have a basic understanding of arrays, the grip I have on the concept is very loose. I understand just enough from the tutorials and the manuals to do what I want, but I'm starting to run into problems that I think could be solved by arrays, but I don't know how to proceed.

So, here it goes.

I plan to have levels in my game. Each level will have a certain number of certain times of enemies that will spawn. I think that it would be very useful to have stored data on each level of my game somewhere instead of filling in a ton of events for the game to have to go through each tick, which I can do with arrays. These arrays would be numbered, and then have the list of enemies as the index, and the number of enemies to spawn on that level as the value.

So the idea that I have is that the battle layout has a blank array of spawn data. Upon starting the layout, an event checks the number of the level the player is on, then fetches the corresponding spawn data from another array and fills the current array with that data. The layout then uses uses that newly filled layout for the actual game, subtracting from that battle array until numbers reach zero. When all numbers reach zero, the level is completed.

The thing I don't know how to do is create that prefilled array. Is there a way to make an array elsewhere, with the data pre-entered, and then have Construct call on that data? My knowledge on arrays is still a bit limited. The array I've used so far is pretty simple. It's a small 1D array with seven values, each which corresponds to a potential "lane" in my game that enemies can spawn in. So I use that array to determine if an enemy is already spawned in a lane, and if it is, it sets the value of the corresponding lane to false. When the enemy dies, that lane is returned to true, and can be used to spawn another enemy.

That's essentially the extent of my knowledge. I've got a system rigged up to fill the array at the start of the layout with the data I need.

B
6
Posts: 14
Reputation: 278

### » Thu Sep 18, 2014 11:41 pm

After cranking away at this for a bit, I may have come upon my solution, maybe.

Would I be loading from a JSON file? I assumed that the load function in Construct wasn't the right one to use since it mentioned using a webpage, but I keep seeing JSON popping up on all the subjects I am Googling.
B
6
Posts: 14
Reputation: 278

### » Fri Sep 19, 2014 1:46 am

"Is there a way to make an array elsewhere?"
why? You can create two or more array in your project,
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
64
S
14
G
3
Posts: 293
Reputation: 7,210

### » Fri Sep 19, 2014 3:21 am

Yes, you're right on the JSON. The way I did my data is by using MS excel, then save it as CSV, then I convert my CSV into C2 JSON format using rexrainbow's csv plugin by loading the CSV into the plugin, then save the array asJSON.

If you want to opt out using 3rd party plugin for your game, then download it using browser object action. The resulting download you can save it as Array.json which is a hard-coded format data that you load using AJAX.

I'm not sure whether is there any better way to do it, but I like the way I'm doing it now because it's error free.
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

### » Fri Sep 19, 2014 7:24 am

Why don't you fill the array in a event/in On layout start?
I'm not a insane, my mother had me tested

I'm an engineer. To save time, just assume I'm never wrong
B
31
S
13
G
4
Posts: 141
Reputation: 4,857

### » Fri Sep 19, 2014 7:38 am

Another way like the json method is using xml. it is formatted a little better that json so that it is human readable and you can use xpath to extract the values.

B
32
S
7
G
2
Posts: 317
Reputation: 2,851