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

Sensor Door

Started by lmic891, 12 February 2015 - 02:49 AM
lmic891 #1
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?
KingofGamesYami #2
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!
lmic891 #3
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!
Quintuple Agent #4
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
Cycomantis #5
Posted 12 February 2015 - 07:12 AM
Try using sensor.getPlayerByNames() vs sensor.getPlayerByName() and see if you have any luck with that.
Bomb Bloke #6
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.