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

0 favourites
  • 8 posts
From the Asset Store
Ninja char for your game! Make your own Shinobi game with this art.
  • 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.

  • How about the third party plugin csv2array (or something like that, I haven't used it)?

  • Here's a rather quickly and badly hacked together way of doing this using

    no

    external plugins.

    [attachment=0:17bvfyp7][/attachment:17bvfyp7]

    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.

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

  • Glad it was of some help.

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

    [quote:3tvhbgnr]@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.

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [attachment=0:19oqteyf][/attachment:19oqteyf]

    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.

    [quote:19oqteyf]

    {"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]]]}

  • 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

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