Regarding config.json files in Lime

When I read the tutorial on using json to make config files my first reaction was that I would end up with lot's and lot's of json files.

Now, i'm not an expert on json and correct me if my code is wrong but can't I just do it like this instead?

In this first file I set it so it reads from a physics file made with physicsEditor.

enemies.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
         "dog":{
                     "physicsFile":["enemyPhysics.json"] -- physicsEditor file.
                     "score": 25,
                     "hitPoints": 2,
                     "sounds":["bark_1.caf", "bark_2.caf", "bark_3.caf"]
                  },
       
            "cat":{
                    "physicsFile":["enemyPhysics.json"] -- physicsEditor file.
                    "score":15,
                    "hitPoints":1,
                    "sounds":["cat_1.caf", "cat_2.caf"]
                   }
 
}

Lime expects a configFile to contain properties for a single object which is whatever object you attach it to in Tiled. Currently you can't create config files with multiple objects that Lime will understand. Naturally you could use these files ( assuming they are valid Json ) yourself in Corona but Lime won't understand them. I will see if I can come up with a way in a future version that could work with these sorts of files.

One thing you could probably do is create your large config files and then give individual tiles properties like isEnemy, isCollectible etc and then in your code you could call lime.loadMap() and then loop through the tiles found applying the properties that you read in from your config file yourself and then add them to the correct tiles. Then call lime.createVisual() etc

As for [] or {}, they are both tables. The difference is that a table created with [] will be number indexed, so would work like a basic array other languages, whereas ones created with {} can be indexed by anything including other tables, so would be like an associative array or dictionary.

Thanks for the answers Graham.

Can I put the json files in a subdirectory then?

In theory you possibly could. I've never actually tried. Certainly worth a go :-)

I didn't think corona supported subdirectories...happy to be corrected as i'd love to stick all my json/wav/png files into a nice ordered structure.
when it comes to json,lime and physics files i have a basic few tile types at the start of the tile set with the physics/propertites attached and use a simple istype:1/2/3/square/circle etc to refer back and just run a loop updating the other tiles, this speeds up my start up time as lime/cornoa doesn't appear to cache the json files.

views:1743 update:2011/10/22 17:28:16
corona forums © 2003-2011