Here's the small snippet:
local label = {{text = "Test",0},{text = "Awesome",0},{text = "Awesomed",0},padding = 0}
Here's what I tried:
print(label[0].text)
But it prints nil, why?
Here's the small snippet:
local label = {{text = "Test",0},{text = "Awesome",0},{text = "Awesomed",0},padding = 0}
Here's what I tried:
print(label[0].text)
But it prints nil, why?
Lua has 1-based arrays. Array[0] is going to return nil everytime unless defined by the program.
print(label[1].test)
Simple and straight-forward. Thanks.
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
There is no such thing as the 0th iteration in a table in Lua. It has to start on the 1st iteration, although I ama aware other programs start at 0. So use table[1] to access the first value.
There is no such thing as the 0th iteration in a table in Lua. It has to start on the 1st iteration, although I ama aware other programs start at 0. So use table[1] to access the first value.
This is commonly knows as nesting ie a nested table. You just have to access the data in the correct way.