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

[OpenPeripheral sensor] Door being messy.. cant figure it out..

Started by plazter, 24 February 2014 - 03:08 PM
plazter #1
Posted 24 February 2014 - 04:08 PM
Hello there pros!
so, i've discovered the great sensor and want to make an automatic door :b but for some reason i just cant wrap my head around it..
i've tryed this:

sensor = peripheral.wrap("left")

while true do
for _, name in pairs(sensor.getPlayerNames()) do
	if name == "Plazter" then
		 -- Open function --
	else
		 -- close function --
	end
sleep(1)
end
- so.. It actually do react on it.. but for some reason get stuck at "open" and dont go further to the close part :(/>
Any idea why ? :)/> and what im doing wrong? :b

Regards Plazter
Edited on 24 February 2014 - 03:08 PM
CometWolf #2
Posted 24 February 2014 - 04:47 PM
The door won't close unless a player other than you approaches it. Try this instead.

sensor = peripheral.wrap("left")
while true do
local door = false
for _, name in pairs(sensor.getPlayerNames()) do
	    if name == "Plazter" then
				 door = true
	    end
end
if door then
  --door open
else
  --door close
end
sleep(1)
end
plazter #3
Posted 24 February 2014 - 04:54 PM
The door won't close unless a player other than you approaches it. Try this instead.

sensor = peripheral.wrap("left")
while true do
local door = false
for _, name in pairs(sensor.getPlayerNames()) do
		if name == "Plazter" then
				 door = true
		end
end
if door then
  --door open
else
  --door close
end
sleep(1)
end

Thanks for the reply man, tho it aint working still :b i've been so close to go nuts cuz i could'nt figure any of it out.. can make it print and such but neh not open a damn door xD! :(/>


Edit: Hey! its working now thanks man! :D/>

Edit 2: But not totally like i would like :b but that got me further, any suggestion on how to use a whitelist system for it? :S
Edited on 24 February 2014 - 03:59 PM
Bomb Bloke #4
Posted 24 February 2014 - 05:39 PM
Make a table with the names of interest:

local users = {["Plazter"] = true,
["Bomb Bloke"] = true,
["etc"] = true}

Then instead of:

if name == "Plazter" then

… just use:

if users[name] then
plazter #5
Posted 24 February 2014 - 06:02 PM
Make a table with the names of interest:

local users = {["Plazter"] = true,
["Bomb Bloke"] = true,
["etc"] = true}

Then instead of:

if name == "Plazter" then

… just use:

if users[name] then
Thanks man ;D