Posted 29 June 2014 - 09:24 PM
I have been trying to do something special with computercraft.
As a student I used to work in the pharmaceutical industry as a labworker.
In this lab we had those sterile zones where they kept their bacteria and in order to access them you had to use a keycard and a code in order to open the door. So I have been trying to design something similar by combining keycard code and using most of nanobobs touchscreen code. I have been working on this for a while and it has been overwhelming me a little bit.
Most of the code is standard except for the last few bits that I changed to my needs.
The problem I have is that I get an error on line 34 (peripheral:34: string expected) but I am not sure why I am getting it.
I used the touchscreen program on it's own without problems. First I thought that I wrapped my peripheral wrong but it doesn't give an error for the lines above so I don't know what is wrong.
Could you people check for errors? And if possible check if my code is correct at all?
Thank you in advance.
edit: The computer, diskdrive and monitor are connected via wired modems. I made sure they are all activated.
As a student I used to work in the pharmaceutical industry as a labworker.
In this lab we had those sterile zones where they kept their bacteria and in order to access them you had to use a keycard and a code in order to open the door. So I have been trying to design something similar by combining keycard code and using most of nanobobs touchscreen code. I have been working on this for a while and it has been overwhelming me a little bit.
--High Security Door System
--peripherals and redstone
--computer, not needed
c=peripheral.wrap("computer_1")
--monitor
m=peripheral.wrap("monitor_2")
--disk drive
d=peripheral.wrap("drive_0")
--redstone
redstoneSide="bottom"
--Code and ID
code="12345"
id="enforcer"
--Keypad input functions
inputs={}
function drawNumpad()
m.clear()
clearInput()
m.setBackgroundColor(128)
m.setCursorPos(2,1)
m.write(" ")
m.setBackgroundColor(256)
m.setCursorPos(1,1)
m.write(" ")
m.setCursorPos(7,1)
m.write(" ")
m.setCursorPos(1,2)
m.write(" ")
m.setBackgroundColor(32768)
m.setCursorPos(2,2)
m.write("1 2 3")
m.setCursorPos(2,3)
m.write("4 5 6")
m.setCursorPos(2,4)
m.write("7 8 9")
m.setCursorPos(2,5)
m.write(" 0 ")
m.setBackgroundColor(256)
m.setCursorPos(1,3)
m.write(" ")
m.setCursorPos(1,4)
m.write(" ")
m.setCursorPos(1,5)
m.write(" ")
m.setCursorPos(7,3)
m.write(" ")
m.setCursorPos(7,4)
m.write(" ")
m.setCursorPos(7,5)
m.write(" ")
m.setBackgroundColor(32)
m.setCursorPos(6,5)
m.write("Ok")
m.setBackgroundColor(16384)
m.setCursorPos(1,5)
m.write("< ")
end
function inputNumber()
event,side,x,y=os.pullEvent("monitor_touch")
if x==2 and y==2 then
digit=1
elseif x==4 and y==2 then
digit=2
elseif x==6 and y==2 then
digit=3
elseif x==2 and y==3 then
digit=4
elseif x==4 and y==3 then
digit=5
elseif x==6 and y==3 then
digit=6
elseif x==2 and y==4 then
digit=7
elseif x==4 and y==4 then
digit=8
elseif x==6 and y==4 then
digit=9
elseif x==4 and y==5 then
digit=0
elseif x>=2 and y==5 then
digit="ok"
elseif x<=6 and y==5 then
digit="clear"
end
if digit=="ok" then
checkNumber()
elseif digit=="clear" then
backspaceInput()
else
if #inputs<5 then
inputs[#inputs+1]=digit
m.setBackgroundColor(128)
m.setCursorPos(#inputs+1,1)
m.write(tostring(digit))
end
end
end
function backspaceInput()
inputs[#inputs]=nil
m.setCursorPos(2,1)
m.write(" ")
m.setCursorPos(2,1)
m.setBackgroundColor(128)
for i,number in pairs(inputs) do
m.write(tostring(number))
end
end
function clearInput()
inputs={}
m.setCursorPos(2,1)
m.setBackgroundColor(128)
m.write(" ")
end
--Keycard input functions
while true do
if disk.isPresent(d) then -- diskdrive side
h = fs.open("disk/passcode", "r")
end
end
--Access system functions
function checkAccess()
if (input==code) and (h.readAll() == id) then
redstone.setOutput(redstoneSide,true)
clearInput()
sleep(5)
redstone.setOutput(redstoneSide,false)
else
clearInput()
end
end
--Access system
checkAccess()
Most of the code is standard except for the last few bits that I changed to my needs.
The problem I have is that I get an error on line 34 (peripheral:34: string expected) but I am not sure why I am getting it.
I used the touchscreen program on it's own without problems. First I thought that I wrapped my peripheral wrong but it doesn't give an error for the lines above so I don't know what is wrong.
Could you people check for errors? And if possible check if my code is correct at all?
Thank you in advance.
edit: The computer, diskdrive and monitor are connected via wired modems. I made sure they are all activated.
Edited on 29 June 2014 - 07:25 PM