0 Favourites

Exporting level to text file? [solved]

  • Hi Guys,

    I have a bit of an odd request. I have a level prototyped on C2 that I would like exported into a text representation. I was wondering if there was some sort of custom script or local save file I could write that could take the position of certain items in my level (such as metal blocks, wooden blocks etc) and create a sort text document grid with those elements represented as letters?

    Thanks guys

    --EDIT--

    Ok guys, I figured it out. If anyone wants an example of how I did it, click here to download my working sample. As I said, my needs were quite specific but I'm sure there's probably someone out there with a similar problem to me. Instead of using an array I decided to go with dictionary as the resulting json file from the download is much easier to process and read as a human being, thanks for all the tips guys :)

  • I've made some progress but I would still appreciate some help. I've created a 2d array that has the size set to the width and height of the level. I've also created a function called save level that has a for loop that goes through the y axis, and within that loop there is another one that goes through the x axis. What I would like this to do is go through each row and search for a particular item. If it find the item on that coordinate then it will assign a value into the array. Once the loop is complete I would like it to some how save that information. Is that at all possible?

  • Well you pretty much answered your own question there ^^; During the loop check if an object is at the position of the current x,y of the array and write some data to it. (If you're using a grid, then cur.x*tilesize, etc.)

    Personally I'd just use a dictionary and "for each" on all the objects I want to save.

  • the way I did it for my game: I design my level in a separate layout or projec and I add an empty textbox. In the event sheet I create an empty string global variable. When I loop trough the elements i want to save, I build an xml string by adding up information about my objects in xml format (position, size, type of sprite...). when it's done building the xml string, I output it in th textbox. And voila, i run the layout and i just need to copy/paste the text into a file. Then in the actual game I parse the xml and rebuild the level. Might not be ideal, but it works fine for me.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Well you pretty much answered your own question there ^^; During the loop check if an object is at the position of the current x,y of the array and write some data to it. (If you're using a grid, then cur.x*tilesize, etc.)

    Personally I'd just use a dictionary and "for each" on all the objects I want to save.

    Thanks for the affirmation :) While I get the logic, I can't quite understand the syntax. Are there any examples of this system you can provide? I've tried looking around myself but haven't been able to find anything

    Here is my attempt, is anyone able to offer some assistance?

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