load char by char and line by line to an array?

Get help using Construct 2

Post » Fri Sep 26, 2014 10:56 pm

Hi,

i have levels for a tilemap made in texteditor, now i thought there must be an easy way to load these txt files to an array to generate the tilemap based on the textfile, but i cant find it. can somebody help me or point me in the wright direction?
i experimented with the textbox object and the text object but didnt foudn what i was searching for.
B
38
S
11
G
5
Posts: 485
Reputation: 5,340

Post » Sat Sep 27, 2014 7:55 am

How about the third party plugin csv2array (or something like that, I haven't used it)?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sat Sep 27, 2014 10:30 am

Here's a rather quickly and badly hacked together way of doing this using no external plugins.

text-to-level.capx


The level is structured as below in the text file, I'm guessing it's the type of thing you are using.

0000000000
0124122320
0155482210
0565322660
0124458650
0565956560
0854856220
0545269550
0154852320
0000000000


Like I said there is probably an easier/elegant way of doing it (probably using REGEX actions). But for a first attempt and in 15mins I think it came out pretty good.

Hope it helps.
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Sat Sep 27, 2014 5:53 pm

wow thank you both! i tryed the csvtoarray plugin and its really great but i didnt finish yet!

@Minor yes, you made exactly what i wanted to do! many thanks! i used the array z axis for storing multiple levels and downloaded the resulting array json data which i now can use in my game!

thanks again everyone!
B
38
S
11
G
5
Posts: 485
Reputation: 5,340

Post » Sat Sep 27, 2014 7:59 pm

Glad it was of some help.

Just a quick note for everyone that the example only works with single digits to represent a tile.

@Minor yes, you made exactly what i wanted to do! many thanks! i used the array z axis for storing multiple levels and downloaded the resulting array json data which i now can use in my game!


More people should do that type of thing. It's something I very often do, hack together a level editor or a way of adding stats for guns or RPG character stats and export it via Construct to json. You know for sure then if Construct exported it, it's going to load it correctly.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Sun Sep 28, 2014 9:51 am

Minor wrote:Glad it was of some help.
You know for sure then if Construct exported it, it's going to load it correctly.

yeah not really... it exports somethign like this
"c2array":true,"size":[10,10,500],"data":
but what it wants for load is
""c2array"":true,""size"":[10,10,500],""data"":

or did i do something wrong?
B
38
S
11
G
5
Posts: 485
Reputation: 5,340

Post » Sun Sep 28, 2014 11:13 am

text-to-level.capx


Added a 2nd layout that loads the saved json into a separate array. You can press "S" in the first layout to save as json.

Works fine for me this way and copying and pasting the json string into a global variable works too but I disabled that action. Below is the level from the text file I created in the first example exported to json.

{"c2array":true,"size":[10,10,1],"data":[[[0],[0],[0],[0],[0],[0],[0],[0],[0],[0]],[[0],[1],[1],[5],[1],[5],[8],[5],[1],[0]],[[0],[2],[5],[6],[2],[6],[5],[4],[5],[0]],[[0],[4],[5],[5],[4],[5],[4],[5],[4],[0]],[[0],[1],[4],[3],[4],[9],[8],[2],[8],[0]],[[0],[2],[8],[2],[5],[5],[5],[6],[5],[0]],[[0],[2],[2],[2],[8],[6],[6],[9],[2],[0]],[[0],[3],[2],[6],[6],[5],[2],[5],[3],[0]],[[0],[2],[1],[6],[5],[6],[2],[5],[2],[0]],[[0],[0],[0],[0],[0],[0],[0],[0],[0],[0]]]}
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Sun Sep 28, 2014 11:49 am

yeah it seems that double " are only needed in the event sheet when the JSON load event is used and the json code is directly pasted there
B
38
S
11
G
5
Posts: 485
Reputation: 5,340


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests