Exporting level to text file? [solved]

Get help using Construct 2

Post » Wed Dec 04, 2013 4:16 pm

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 :)dmakinde2013-12-05 12:21:33
B
5
Posts: 29
Reputation: 733

Post » Wed Dec 04, 2013 10:02 pm

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?
B
5
Posts: 29
Reputation: 733

Post » Thu Dec 05, 2013 1:20 am

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.
Image
B
242
S
29
G
13
Posts: 1,787
Reputation: 18,685

Post » Thu Dec 05, 2013 6:55 am

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.OlivierC2013-12-05 06:58:03
B
12
S
5
G
2
Posts: 132
Reputation: 2,627

Post » Thu Dec 05, 2013 8:37 am

[QUOTE=MadFactory] 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.[/QUOTE]

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?dmakinde2013-12-05 09:32:55
B
5
Posts: 29
Reputation: 733


Return to How do I....?

Who is online

Users browsing this forum: el3um4s, marcinkowski, marcoscodas, Ryan Kocourek, TheSupreme, TylerJS and 11 guests