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

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

Or something similar but for objects without using physicsEditor.

objects.json

{  
 "woodBox":{  
 "properties":{  
 "bodyType":"static",  
 "bounce":1.0,  
 "friction":0.5,  
 "density":1.0,  
 "isSensor":false  
 },  
 },  
  
 "ironBlock":{  
 "properties":{  
 "bodyType":"static",  
 "bounce":0.0,  
 "friction":1.5,  
 "density":10.0,  
 "isSensor":false  
 }  
 }  
  
}  

If I would do it something like this then I would only have a few .json files or if I wanted to add everything into one large file however that would be very painful to edit.

But anyways, it seems like having files for objects, enemies, collectibles and player would be a good solution.

What it I just trace the shape with PhysicsEditor and set all values to 0, does lime override those values if I set the properties manually in the objects.json file?

Overriding the objects properties manually;
objects.json

{  
 "woodBox":{  
 "properties":{  
 "physicsFile":["objectsPhysics.json"] -- physicsEditor file for tracing only  
 "bodyType":"static",  
 "bounce":1.0,  
 "friction":0.5,  
 "density":1.0,  
 "isSensor":false  
 },  
 },  
  
 "ironBlock":{  
 "properties":{  
 "physicsFile":["objectsPhysics.json"] -- physicsEditor file for tracing only  
 "bodyType":"static",  
 "bounce":0.0,  
 "friction":1.5,  
 "density":10.0,  
 "isSensor":false  
 }  
 }  
  
}  

In the config tutorial on the Lime website, when you set up the config file in the object properties panel you reference to the config file. How would I reference in tiled so it pick the right objects property like in my second example?

Will it by automatic find the right property if the object name matches?

Last question, since {} are objects and [] are arrays shouldn’t I set the object properties as an [] array? Just thinking, an object has an array of properties…

If my json structure is wrong please let me know.
Thanks guys. [import]uid: 34126 topic_id: 16543 reply_id: 316543[/import]

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. [import]uid: 5833 topic_id: 16543 reply_id: 61822[/import]

Thanks for the answers Graham.

Can I put the json files in a subdirectory then? [import]uid: 34126 topic_id: 16543 reply_id: 61861[/import]

In theory you possibly could. I’ve never actually tried. Certainly worth a go :slight_smile: [import]uid: 5833 topic_id: 16543 reply_id: 61866[/import]

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. [import]uid: 80828 topic_id: 16543 reply_id: 62291[/import]

You can put assets, soundfiles etc in subdirectories but not lua files. They have to be in the root directory, same place where you keep your main.lua.

However, you can put lua files in sub directories if you have access to daily builds. In a build some time ago they added that feature and you would require files like this if you decide to go that route:

local level1 = require(“worlds.levels.level1”)

Note that you don’t use / for specifying the directory path, you must use a " . "

When it comes to json files in sub directories in tiled, I’m testing it now but I’m not sure if I should go with /, | or . to specify the path in tiled.

Any suggestions Graham? [import]uid: 13560 topic_id: 16543 reply_id: 62894[/import]

Assuming json files are considered normal resources by Corona, I would go with the / however if Corona things they are code files ( which I guess it doesn’t ) then go with the .

Hopefully they will either work or give you a helpful error message :slight_smile: [import]uid: 5833 topic_id: 16543 reply_id: 62997[/import]

I tried using / for file path with json files in sub directories and it worked.

After playing around with Tiled and Lime for a few days I have a few questions;

1, How do I position the map with x and y? I have tried map.x and map.y and it didn’t change the position. What if I wanted to offset my map to make space for a toolbar or controls, how do I do that?

2, Since I can add properties to tiles, what is the purpose with adding an object layer and assign isGround, HasBody etc?

3, When animating characters within Tiled, does the frame count start from top left and continue on the next row after the first line is done?

4, Performance wise, my player has a total of 10 frames for walk, jump and idle. How much would that affect performance in comparison to spritesheets?
I have thought a little on question 2, should I use object layer in Tiled when specifying larger groups of tiles such as the ground or walls? (non dynamic objects)

It’s great fun to work with Lime since it’s a more visual way of creating games.

Thanks for all the help.
David [import]uid: 34126 topic_id: 16543 reply_id: 63656[/import]

  1. This can be used for that: http://justaddli.me/api.php?c=map&m=setPosition

  2. Adding those properties to an ObjectLayer won’t do anything, however you can add whatever other properties you like to it that you can then use in your game for things if you like.

  3. Yes it does.

  4. Depends how large your images are and if they are power of two. However it would affect memory usage more than speed really ( unless you go over memory constraints )

And yea, that is the plan as that was requested however I haven’t had a chance to implement it yet. [import]uid: 5833 topic_id: 16543 reply_id: 64273[/import]