2 posts
Posted 12 February 2015 - 03:49 AM
I found several threads about this, although none have helped…
Here's my code so far:
sensor=peripheral.wrap("right")
while true do
local door=false
for _, name in pairs(sensor.getPlayerNames()) do
if name=="lmic891" then
door=true
end
if door then
redstone.setoutput("left", true)
else
redstone.setoutput("left", false)
end
sleep(1)
end
As is, it gives me a nil error on line 4. Any ideas?
3057 posts
Location
United States of America
Posted 12 February 2015 - 04:18 AM
Is it giving you 'attempt to call nil' or 'attempt to index ? (a nil value)'?
Former - getPlayerNames isn't a valid method for that peripheral
Latter - There is not a sensor on side "right"
PS: Use code tags:
--#I'm in code tages!
2 posts
Posted 12 February 2015 - 04:44 AM
It was actually both, now giving an error of door:4: Not enough arguements, first missing: username
(Also would probably help if I said I was using the OpenPeripheral Sensor in 1.7.10, program name door)
New code:
sensor=peripheral.wrap("left")
while true do
local door=false
for _, name in pairs(sensor.getPlayerByName()) do
if name=="lmic891" then
door=true
end
if door then
redstone.setoutput("right", true)
else
redstone.setoutput("right", false)
end
sleep(1)
end
Thanks KingofGamesYami for the /code hint!
113 posts
Location
This page
Posted 12 February 2015 - 06:41 AM
Judging by the error and the name of the method, I would say getPlayerByName() needs a username and it returns that players info.
I have not really used OP Sensors that much but either it will do an exact match of the name, or anyone with the given string in their name
Edited on 12 February 2015 - 05:43 AM
59 posts
Posted 12 February 2015 - 07:12 AM
Try using sensor.getPlayerByNames() vs sensor.getPlayerByName() and see if you have any luck with that.
7083 posts
Location
Tasmania (AU)
Posted 12 February 2015 - 09:09 AM
If you run:
openp/docs <side>
… you'll get a list of the functions available to the peripheral on that side (assuming it's an OpenPeripheral peripheral).
If you run:
openp/docs <side> <function name>
… you'll get the details on how to use that particular function.