This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
GamerNebulae's profile picture

Choosing a value from a table that has multiple values

Started by GamerNebulae, 31 May 2014 - 05:28 PM
GamerNebulae #1
Posted 31 May 2014 - 07:28 PM
Hello everyone!

I am working on a program and I was wondering if I could specifically get a value from a table if I know the index. For example:

Table = {}

Table[index] = {"1", "2", "3", "4"}

I know the index and I know what value I want to use, but how can I say that in Lua? (I want to know what the third value in that table is for example)
Dog #2
Posted 31 May 2014 - 07:39 PM
I believe that would be Table[index][3] (only because "3" is the third value in the table).

If your table was

Table[index] = { "cat", "kibble", "chair leg", "fire hydrant" }
the query Table[index][3] would return "chair leg"
Edited on 31 May 2014 - 05:41 PM
GamerNebulae #3
Posted 31 May 2014 - 08:13 PM
I believe that would be Table[index][3] (only because "3" is the third value in the table).

If your table was

Table[index] = { "cat", "kibble", "chair leg", "fire hydrant" }
the query Table[index][3] would return "chair leg"

As I suspected. Thanks for clarifying it!
Dog #4
Posted 31 May 2014 - 08:19 PM
Happy to help :)/>