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

printing table´s with unknown keys

Started by blipman17, 27 June 2013 - 04:42 AM
blipman17 #1
Posted 27 June 2013 - 06:42 AM
hello evereyone,

i´m trying to print the content from a table from wich i don´t know the keys of. I need it to get the peripheral methods for that peripheral.
to be honest i am not brilliant with tables but only understand the value assignment of them an how to use them.
but i don´t know how to just print them.
i´ve read something about ipair() or pair() but don't know what to do.

this is the code as i have it so far.


pipe=peripheral.wrap("front")
tabl={}
pipe.setTurtleConnect(true)
tabl=pipe.peripheral.GetMethods("front")
i= ipair(tabl)
print()

if someone can help me, it would be great.
theoriginalbit #2
Posted 27 June 2013 - 06:52 AM

for k,v in pairs(peripheral.getMethods("front")) do
  print(k,':',v)
end
blipman17 #3
Posted 27 June 2013 - 10:19 AM
thank you so much.

i am already trying it.
but… it doesn't fit on a screen of a turtle.
so i have to do the first value's myself
can you tell me how the for in do statement works?
is it that for every key that will be stored in k that is given from pairs(), you print v/the value stored?
apemanzilla #4
Posted 27 June 2013 - 10:23 AM
The for x,y in pairs(table) do statement goes through every key in a table with x as the key and y as that key's value.