I'm using Tiled and I'm trying to access a table. Help?
Posted: Mon Mar 23, 2015 5:36 am
So this is my map.lua
My actual data table (at the end of the code) is much larger I just shortened it for this post. I'm trying to access the first number with
So "map" gets into the file, ".layers" gets me into the layers table, the [1] gets me into the unnamed sub-table, ".data" gets me into the data table, and the last [1] should get me that first digit. But it says "string expected, got table". It says the same thing if I make it and if I make it it returns nil. What am I doing wrong?
Code: Select all
return {
version = "1.1",
luaversion = "5.1",
tiledversion = "0.11.0",
orientation = "orthogonal",
width = 45,
height = 45,
tilewidth = 16,
tileheight = 16,
nextobjectid = 1,
properties = {},
tilesets = {
{
name = "Default",
firstgid = 1,
tilewidth = 16,
tileheight = 16,
spacing = 0,
margin = 0,
image = "../images/tileset.png",
imagewidth = 160,
imageheight = 160,
tileoffset = {
x = 0,
y = 0
},
properties = {},
terrains = {},
tiles = {
{
id = 0,
properties = {
["Solid"] = "Solid"
}
}
}
}
},
layers = {
{
type = "tilelayer",
name = "Background",
x = 0,
y = 0,
width = 45,
height = 45,
visible = true,
opacity = 1,
properties = {},
encoding = "lua",
data = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
}
}
}
}
Code: Select all
map.layers[1].data[1]
Code: Select all
map.layers[1].data[1][1]
Code: Select all
map.layers[1].data[1][1][1]