5 posts
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.
259 posts
Posted 05 June 2014 - 07:38 AM
What code do you have so far?
5 posts
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
8543 posts
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.
5 posts
Posted 05 June 2014 - 07:49 PM
Using the code I posted got
bios:339: [string "door"] :8: '<eof>' expected
8543 posts
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?
5 posts
Posted 06 June 2014 - 07:04 PM
No worries managed to work it through myself and fixed it. Thanks for the help.