Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to have a table in a table in LUA? I'm trying it but it gets printed nil.

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?

3 comments

1

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.

0

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.

0

This is commonly knows as nesting ie a nested table. You just have to access the data in the correct way.

1 answer

✓ Accepted answer

Lua has 1-based arrays. Array[0] is going to return nil everytime unless defined by the program.

print(label[1].test)

1 comment

1

Simple and straight-forward. Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.