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

Automatic Door Program

Started by qwerty1234, 04 June 2014 - 11:31 PM
qwerty1234 #1
Posted 05 June 2014 - 01:31 AM
I'm new to cc and have no idea what im doing. From tutorials/the wiki ive got a computer with a opencc proximity sensor to its left, a block under the block the doors would be on.

I'm wanting to make an automatic door. Any help appreciated.
CCJJSax #2
Posted 05 June 2014 - 07:38 AM
What code do you have so far?
qwerty1234 #3
Posted 05 June 2014 - 01:51 PM
This is what I got from the wiki, and from what i can tell its what I need, just no idea how to implement it.

os.loadAPI("ocs/apis/sensor")

– the location of the redstone lamp relative to the sensor
local offset = {
X = 1,
Y = 1,
Z = 0
}

– how close a player has to be to activate the lamp
local radius = 5

– find the distance from the player position to the offset
function distance(pos)
local xd = pos.X - offset.X
local yd = pos.Y - offset.Y
local zd = pos.Z - offset.Z
return math.sqrt(xd*xd + yd*yd + zd*zd)
end


local proximity = sensor.wrap("left")
while true do
local signal = false
local targets = proximity.getTargets()
for k, v in pairs(targets) do
if distance(v.Position) < radius then
signal = true
end
end
rs.setOutput("top", signal)
end
Lyqyd #4
Posted 05 June 2014 - 07:39 PM
Yeah, that looks about right. Try it out in-game and see if it does what you're looking for. If you need a whitelist added to it, we can help you rearrange the code to work that way.
qwerty1234 #5
Posted 05 June 2014 - 07:49 PM
Using the code I posted got

bios:339: [string "door"] :8: '<eof>' expected
Lyqyd #6
Posted 05 June 2014 - 10:08 PM
I'm not sure that's the code you posted, since that's not an error I'd expect to see there. Can you verify, character by character, that the code is exactly the same, if you re-typed it?
qwerty1234 #7
Posted 06 June 2014 - 07:04 PM
No worries managed to work it through myself and fixed it. Thanks for the help.