Jump to content




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


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

#1 plazter

  • Members
  • 134 posts

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 by plazter, 24 February 2014 - 04:08 PM.


#2 CometWolf

  • Members
  • 1,283 posts

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


#3 plazter

  • Members
  • 134 posts

Posted 24 February 2014 - 04:54 PM

View PostCometWolf, on 24 February 2014 - 04:47 PM, said:

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 by plazter, 24 February 2014 - 04:59 PM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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


#5 plazter

  • Members
  • 134 posts

Posted 24 February 2014 - 06:02 PM

View PostBomb Bloke, on 24 February 2014 - 05:39 PM, said:

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





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users