Jump to content




printing table´s with unknown keys


  • You cannot reply to this topic
3 replies to this topic

#1 blipman17

  • Members
  • 92 posts

Posted 27 June 2013 - 05: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.

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 27 June 2013 - 05:52 AM

for k,v in pairs(peripheral.getMethods("front")) do
  print(k,':',v)
end


#3 blipman17

  • Members
  • 92 posts

Posted 27 June 2013 - 09: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?

#4 apemanzilla

  • Members
  • 1,421 posts

Posted 27 June 2013 - 09: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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users