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

How to read tables?

Started by marceloclp, 03 May 2014 - 06:19 PM
marceloclp #1
Posted 03 May 2014 - 08:19 PM
I'm having some hard time trying to understand how to read the output of the peripheral API, like peripheral.getNames().

The output given by the computer is always something like

table: 2ed2cd7e

Yep, I don't know much about Lua.
Lyqyd #2
Posted 03 May 2014 - 08:26 PM
So, when you get the table, you can iterate through it to see its contents. Try doing this:


local names = peripheral.getNames()
print("names contains:")
for k, v in pairs(names) do
  print(tostring(k)..": "..tostring(v))
end

That will let you see what's inside it.
marceloclp #3
Posted 03 May 2014 - 08:37 PM
Oh! I didn't know you had the for in loop in Lua. Cool!
Sir_Mr_Bman #4
Posted 03 May 2014 - 08:39 PM
If you are new to lua this tutorial from the website may help you out