Tiled's New Lua Export Option

Okay, this is really interesting. I just updated to the latest version of Tiled yesterday and was surprised to see one of the export options is Lua – it actually spits out Lua code that can be easily used to get all the info about the levels, tiles, etc. 
 
No need anymore to actually read/parse the .tmx file. I’ll paste a small map down below.
 
Looking at that you can get data for a layer like this:
 
[lua]

local myMap = require(“tileMapTest”)

local tileData = myMap.layers[1].data

local tilePic = myData.tilesets[1].image

[/lua]

A person *could* continue to pull data from the .tmx file but I’m wondering if that’s a good use of code or not.

[lua]

– this in a file called tileMapTest.lua
return {
  version = “1.1”,
  luaversion = “5.1”,
  orientation = “orthogonal”,
  width = 15,
  height = 10,
  tilewidth = 32,
  tileheight = 32,
  properties = {},
  tilesets = {
    {
      name = “tileset-platformer”,
      firstgid = 1,
      tilewidth = 32,
      tileheight = 32,
      spacing = 0,
      margin = 0,
      image = “tileset-platformer.png”,
      imagewidth = 192,
      imageheight = 544,
      properties = {},
      tiles = {
        {
          id = 73,
          properties = {
            [“points”] = “200”
          }
        }
      }
    }
  },
  layers = {
    {
      type = “tilelayer”,
      name = “Tile Layer 1”,
      x = 0,
      y = 0,
      width = 15,
      height = 10,
      visible = true,
      opacity = 1,
      properties = {},
      encoding = “lua”,
      data = {
        0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 65, 51, 52, 53, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 65, 0, 0, 58, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 65, 0, 26, 27, 28, 0, 0, 13, 14,
        0, 0, 0, 0, 0, 0, 70, 26, 32, 33, 34, 29, 0, 19, 20,
        0, 74, 0, 0, 0, 25, 27, 32, 33, 33, 33, 35, 0, 19, 20,
        4, 5, 6, 0, 0, 31, 33, 33, 33, 33, 33, 35, 0, 19, 20,
        10, 11, 12, 0, 0, 31, 33, 33, 33, 33, 33, 35, 0, 19, 20
      }
    }
  }
}
[/lua]

With CoronaTiled, we’re making it able to do all; it just reads the file name and checks for “.json”, “.tmx”, or “.lua”.

Just a thought :slight_smile:

C

TMX isn’t really working right now, and I’m certainly not planning on investing much time to it :) 

The only watch out is the the LUA option doesn’t support as much as the TMX/JSON format.

@J.A.Whye The JSON format is probably the best open for both speed and compatibility.

Also, if you think 0.9 is cool, check out the daily builds with Rotation and other interesting features… (Windows only)

http://files.mapeditor.org/daily/

@No2Games:
I was going to look into making TMX support… Complete newbie for XML, though, but if I can do it, I’ll finally have done something :slight_smile:

You’re right though - JSON is probably the best. It doesn’t save an entirely new thing in the package.loaded table. Although TMX should be about the same as JSON if it ever gets finished.

C

I would imagine the Lua export will catch up to JSON/TMX – I can’t think it would be hobbled on purpose. The nice thing about using the Lua export is it’s one less level of translation. Doesn’t matter for speed sake or anything like that, just a general “simpler is usually better” principle. :slight_smile:

I’m a Mac zealot and while I *can* run Windows, unless I’m doing it to test my own apps I’d rather not. I’ll just wait for the Tiled public release. (But I did go over and check out the info on his blog – cool stuff!)  ;)

 Jay

Agreed. At least with Lua export you wouldn’t need to include the JSON module.

Yeah, the upcoming stuff makes a lot more sense for Corona. It’s better suited for free form placement of images in 2D space than a bunch of small tiles.

All the latest daily build of tiled is lacking is xScale,yScale handles (you can set that manually as a property) and loading arbitrary sized tiles. I fear though it could be 6 months before those make it into a usable release.

With CoronaTiled, we’re making it able to do all; it just reads the file name and checks for “.json”, “.tmx”, or “.lua”.

Just a thought :slight_smile:

C

TMX isn’t really working right now, and I’m certainly not planning on investing much time to it :) 

The only watch out is the the LUA option doesn’t support as much as the TMX/JSON format.

@J.A.Whye The JSON format is probably the best open for both speed and compatibility.

Also, if you think 0.9 is cool, check out the daily builds with Rotation and other interesting features… (Windows only)

http://files.mapeditor.org/daily/

@No2Games:
I was going to look into making TMX support… Complete newbie for XML, though, but if I can do it, I’ll finally have done something :slight_smile:

You’re right though - JSON is probably the best. It doesn’t save an entirely new thing in the package.loaded table. Although TMX should be about the same as JSON if it ever gets finished.

C

I would imagine the Lua export will catch up to JSON/TMX – I can’t think it would be hobbled on purpose. The nice thing about using the Lua export is it’s one less level of translation. Doesn’t matter for speed sake or anything like that, just a general “simpler is usually better” principle. :slight_smile:

I’m a Mac zealot and while I *can* run Windows, unless I’m doing it to test my own apps I’d rather not. I’ll just wait for the Tiled public release. (But I did go over and check out the info on his blog – cool stuff!)  ;)

 Jay

Agreed. At least with Lua export you wouldn’t need to include the JSON module.

Yeah, the upcoming stuff makes a lot more sense for Corona. It’s better suited for free form placement of images in 2D space than a bunch of small tiles.

All the latest daily build of tiled is lacking is xScale,yScale handles (you can set that manually as a property) and loading arbitrary sized tiles. I fear though it could be 6 months before those make it into a usable release.