How to get something from a table in a table

for example, i have this table.

local test = {
[5] = 5,
[7] = 7,
["Fruit"] = "Apple"
["Apple"] = *test["Fruit"]*?
}

i expected [“Apple”] to be set as “Apple” but instead it gave me an error.

1 Like

If you want to get something from a table use Table[Item] to get and use Table[Item] = something. Tell me if you have any other problems.

what?
elaborate please

abcdefghijklmaskg

Are you trying to get something from a table?

You can’t reference test[“Fruit”] from within the table because at that point, test has not been instantiated yet.

What you need to do is set test[“Apple”] 's value to test[“Fruit”] from outside of the table. Here is what I mean:

local test = {
  [5] = 5,
  [7] = 7,
  ["Fruit"] = "Apple"
}

test["Apple"] = test["Fruit"] --You can now access test["Fruit"] now that the table is instantiated

my brain clearly not working correctly at late hours…

Just trying to clarify my comment because it’s kind of unclear, you can’t reference a table from within itself, meaning you can’t reference test or test[“Fruit”] from within the table, because the table had not been completely instantiated yet.

yeah i did get that, you don’t need to write that

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.