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

How to make an Openperipheral-addon sensor door.

Started by feedmecookies, 08 June 2016 - 05:33 PM
feedmecookies #1
Posted 08 June 2016 - 07:33 PM
Sorry if this comes out "Nooby" i have personally never use the forum and are not the best programmer, but my questions is how can i get the players name to show. i have no fully functional program, however i would like to know why i get an odd table when using the sensor to try to get the name of the people inside the range :

code:

sensor = peripheral.wrap("top") – where the sensor is located–

players = sensor.getPlayers()– when i try to print it i only get an odd table containing something like table: 21186106, how can i fix this?

print(players)

how can i get this to only show like(FeedMeCookies, instead of table: 21186106). i have tried textutils.serialize to help out, but nothing seems to help. I just wanna know the name of players inside.
Dog #2
Posted 08 June 2016 - 09:03 PM
Since players is a table, you'll need to iterate through that table to get what you want. Try this…

local sensor = peripheral.wrap("top")
local players = sensor.getPlayers()
for k, v in pairs(players) --# start a generic loop
  print(k .. " / " .. v) --# print each key/value pair in the table
  if type(v) == "table" then --# if the value is another table, then iterate though that table
    for i, n in pairs(v) do --# start another generic loop
      print(i .. " / " .. n) --# print each key/value pair in the table
    end
  end
end

This will look through the players table and print out all key/value pairs in that table - it will also look for sub-tables and print those keys/values out as well. I haven't worked with with any sensor mods in quite awhile, but this should get us the info we need to find what you want. Try the code and let me know what it outputs.
feedmecookies #3
Posted 10 June 2016 - 03:45 AM
Thank you, i am still a little unfamiliar with tables and that. I want to thank you for your help. Now it will be a little less irritating for me to figure out on my own. cheers. Btw how do you only get the name to show up and not he uuid, i get a bunch of letters AND my name, but how do i only get the name? if there is no possibility thats fine i can manage without
Edited on 10 June 2016 - 03:24 AM