Code: Select all
a = {a, b}
a.b = {
{
c = 1
}
}
print(a.b.c) --> nil instead of 1
Code: Select all
{
c = 1
}
Code: Select all
a = {a, b}
a.b = {
{
c = 1
}
}
print(a.b.c) --> nil instead of 1
Code: Select all
{
c = 1
}
Well, a.b[1].c it exactly what I need, thank youzorg wrote: ↑Fri Jan 22, 2021 10:31 pm With a = {a, b}, you're actually doing this: a = {[1] = a, [2] = b}, and at that time, both a and b are either nil, or whatever you set those, if you did.
The second issue is you doubling up the brackets, so again, you'll get this:
a.b = {[1] = {['c'] = 1}}
which can be printed with a.b[1].c instead... lose the extra brackets and it'll work:
a = {}
a.b = {
c = 1
}
You can also do it with the opening bracket on its own line, lua shouldn't complain:
a = {}
a.b =
{
c = 1
}
Code: Select all
tileset = {
{
<Data>
}
}
It's for a reason - Tiled has to have a way to denote multiple tilesets. Your quick snippet actually says "tileset" instead of "tilesets", so I guess that's where the confusion came from. If you only use one tileset, then it's absolutely correct to just take the first element from the table using [1]. I guess that for some use cases it would be better if Tiled exported it like:GVovkiv wrote: ↑Sat Jan 23, 2021 12:45 am Main problem with it I experience in Tiled
When it creat .lua file, it put some tables likewith double brackets instead of oneCode: Select all
tileset = { { <Data> } }
And it sucks
Code: Select all
tilesets = {
ground = { <Data> }
trees = { <Data> }
}
("tileset" just for example)ohai wrote: ↑Sat Jan 23, 2021 9:47 amIt's for a reason - Tiled has to have a way to denote multiple tilesets. Your quick snippet actually says "tileset" instead of "tilesets", so I guess that's where the confusion came from. If you only use one tileset, then it's absolutely correct to just take the first element from the table using [1]. I guess that for some use cases it would be better if Tiled exported it like:GVovkiv wrote: ↑Sat Jan 23, 2021 12:45 am Main problem with it I experience in Tiled
When it creat .lua file, it put some tables likewith double brackets instead of oneCode: Select all
tileset = { { <Data> } }
And it sucksbut I guess they didn't put that much thought into it. Or maybe I'm wrong and it's more important for them to have tilesets ordered and be able to use ipairs() instead of pairs() to iterate over.Code: Select all
tilesets = { ground = { <Data> } trees = { <Data> } }
Code: Select all
layers = {
{ -- first layer
*layer 1 objects*
}
{ -- 2nd layer
*layer 2 objects*
}
}
Code: Select all
l = 1 -- layer index, i guess
print(layers[l])
GVovkiv wrote: ↑Fri Jan 22, 2021 10:21 pm So, i kinda new to lua and i encountered with problem:
so there exist way to get tables like this without deleting this brackets?:Code: Select all
a = {a, b} a.b = { { c = 1 } } print(a.b.c) --> nil instead of 1
Code: Select all
{ c = 1 }
Code: Select all
print(a.b[1].c)
Question was already solved, but thanks for answer anywaydarkfrei wrote: ↑Sat Jan 23, 2021 7:49 pmGVovkiv wrote: ↑Fri Jan 22, 2021 10:21 pm So, i kinda new to lua and i encountered with problem:
so there exist way to get tables like this without deleting this brackets?:Code: Select all
a = {a, b} a.b = { { c = 1 } } print(a.b.c) --> nil instead of 1
Code: Select all
{ c = 1 }
Code: Select all
print(a.b[1].c)
Users browsing this forum: Google [Bot] and 179 guests