How do I create level data? (Arrays question)

0 favourites
  • 6 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • 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.

    Thank you for your time!

  • 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.

  • "Is there a way to make an array elsewhere?"

    why? You can create two or more array in your project,

  • 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.

  • Why don't you fill the array in a event/in On layout start?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

    Try googling "online json tool" or "online xml tool" those should help you build your files faster without needing to download software/plugins

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