214 posts
Posted 31 August 2012 - 10:29 AM
ok so i got this code for a keycard system. if you put a certain floppy disk in a disk drive it activates a redstone signal. the way this works is there is a password, then there is a file on the disk called access. now if the password matches the password written in the access file on the disk the door opens. if it doesent match it does nothing. now what i want to happen is if the pass doesent match it activates a different redstone signal at a different side of the computer. at the top of the code you can see password in qoutes. the word written in this must match the word written in "access" on the floppy for the door to open. please could someone tell me how to make it so if it doesent match it sends out a redstone signal at a configurable side for a configurable time. so using the sleep(5) string for the time and im not sure how to do the redstone part. please someone help thanks -Cheeky heres the code:
password = "password"
debug_char = "0"
term.clear()
function mainLoop()
while(true) do
event, driveSide = os.pullEventRaw()
if(event=="disk" and driveSide) then
path = disk.getMountPath(driveSide)
if(path) then
path = path.."/access"
file = fs.exists(path) and io.open(path, "r") or nil
end
disk.eject(driveSide)
if(file and file:read()==password) then
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", false)
end
if(file) then file:close() file = nil end
elseif(debug_char and event=="char" and driveSide==debug_char) then return("break") end
end
end
rs.setOutput("left", false)
sfile = io.open("/startup", "w")
sfile:write('shell.run("keycard")')
sfile:close()
repeat
ok, err, val = pcall(mainLoop)
if(not ok and err) then
if(err=="Terminated") then print ("Access denied.")
else
print(err)
end
end
until(ok and err=="break")
214 posts
Posted 31 August 2012 - 12:25 PM
Help pleaseee
236 posts
Location
Germany
Posted 31 August 2012 - 04:56 PM
ill rewrite this to how i think it would be better to look at it
password = "password"
debug_char = "0"
function check(ds)
path = disk.getMountPath(ds)
if(path) then
path = path.."/access"
if(fs.exists(path)) then
return fs.open(path,"r")
else
return nil
end
end
function handle(type,ds)
if(type==0) then
disk.eject(ds)
rs.setOutput("right", true)
sleep(3)
rs.setOutput("right", false)
else
disk.eject(ds)
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", false)
end
term.clear()
while(true) do
event, driveSide = os.pullEventRaw()
if(event=="disk") then
diskdata = check(driveSide)
if(diskdata ~= nil) then
if(diskdata:readAll()==password) then
handle(2,driveSide)
else
handle(0,driveSide)
end
else
handle(0,driveSide)
end
end
214 posts
Posted 01 September 2012 - 02:46 PM
ill rewrite this to how i think it would be better to look at it
password = "password"
debug_char = "0"
function check(ds)
path = disk.getMountPath(ds)
if(path) then
path = path.."/access"
if(fs.exists(path)) then
return fs.open(path,"r")
else
return nil
end
end
function handle(type,ds)
if(type==0) then
disk.eject(ds)
rs.setOutput("right", true)
sleep(3)
rs.setOutput("right", false)
else
disk.eject(ds)
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", false)
end
term.clear()
while(true) do
event, driveSide = os.pullEventRaw()
if(event=="disk") then
diskdata = check(driveSide)
if(diskdata ~= nil) then
if(diskdata:readAll()==password) then
handle(2,driveSide)
else
handle(0,driveSide)
end
else
handle(0,driveSide)
end
end
thanks so much, you have helped me a lot for computer craft, il go test this now on my server and il tell you if it works :)/>/> thanks again so much
214 posts
Posted 01 September 2012 - 03:13 PM
ill rewrite this to how i think it would be better to look at it
password = "password"
debug_char = "0"
function check(ds)
path = disk.getMountPath(ds)
if(path) then
path = path.."/access"
if(fs.exists(path)) then
return fs.open(path,"r")
else
return nil
end
end
function handle(type,ds)
if(type==0) then
disk.eject(ds)
rs.setOutput("right", true)
sleep(3)
rs.setOutput("right", false)
else
disk.eject(ds)
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", false)
end
term.clear()
while(true) do
event, driveSide = os.pullEventRaw()
if(event=="disk") then
diskdata = check(driveSide)
if(diskdata ~= nil) then
if(diskdata:readAll()==password) then
handle(2,driveSide)
else
handle(0,driveSide)
end
else
handle(0,driveSide)
end
end
ok it dident work. i tried my own code as well but that dident work either. what i did was with my code, after the rs.setOutput("right, true/false)
i added
else
rs.setOutput("left", true/false)
the keycard bit worked but if the wrong disk got inserted the other redstone output dident get powerd. please could you try my code ingame to see how it works because i need a few features/ for example my code locks down the computer so that no one can use it. to use my code just put a access file with "password" in it and a file called keycard with the code above in it. put both on a disk and on a computer then run keycard on the computer.
236 posts
Location
Germany
Posted 02 September 2012 - 03:49 PM
i fixed my code after finally getting mc back to working -.-
password = "password"
debug_char = "0"
function check(ds)
path = disk.getMountPath(ds)
if(path) then
path = path.."/access"
if(fs.exists(path)) then
return fs.open(path,"r")
else
return nil
end
end
end
function handle(type,ds)
if(type==0) then
disk.eject(ds)
rs.setOutput("right", true)
sleep(3)
rs.setOutput("right", false)
else
disk.eject(ds)
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", false)
end
end
term.clear()
while(true) do
event, driveSide = os.pullEventRaw()
if(event=="disk") then
diskdata = check(driveSide)
if(diskdata ~= nil) then
if(diskdata:readAll()==password) then
handle(2,driveSide)
else
handle(0,driveSide)
end
else
handle(0,driveSide)
end
end
end
was missing some end's this should work
214 posts
Posted 03 September 2012 - 02:34 PM
i fixed my code after finally getting mc back to working -.-
password = "password"
debug_char = "0"
function check(ds)
path = disk.getMountPath(ds)
if(path) then
path = path.."/access"
if(fs.exists(path)) then
return fs.open(path,"r")
else
return nil
end
end
end
function handle(type,ds)
if(type==0) then
disk.eject(ds)
rs.setOutput("right", true)
sleep(3)
rs.setOutput("right", false)
else
disk.eject(ds)
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", false)
end
end
term.clear()
while(true) do
event, driveSide = os.pullEventRaw()
if(event=="disk") then
diskdata = check(driveSide)
if(diskdata ~= nil) then
if(diskdata:readAll()==password) then
handle(2,driveSide)
else
handle(0,driveSide)
end
else
handle(0,driveSide)
end
end
end
was missing some end's this should work
lost access to the internet for a bit so i dident get a chance to try your code, but i made a fix for my self.
after rs.setOutput("left", true) i added the following
rs.setOutput("right", false") <– this turns the alarm signal after the right disk is put it
sleep(3)
rs.setOutput("left", false)
else
rs.setOutput("right", true)
end
its probaly not the best way of doing it, but thats what i managed to come up with
.
1548 posts
Location
That dark shadow under your bed...
Posted 03 September 2012 - 03:18 PM
Ok, I am going to try write a new code, you can try it if you like
local password='pass'
local sides={'right','left'}
local function check(sSide)
if type(disk.getMountPath(sSide))=='string' then
local path=disk.getMountPath(sSide)..'/access'
if fs.exists(path)==true then
return fs.open(path,'r').readAll()
else
return nil
end
end
end
local function pulse(sideNum,delay)
rs.setOutput(sides[sideNum],true)
sleep(delay)
rs.setOutput(sides[sideNum],false)
end
while true do
term.clear()
term.setCursorPos(1,1)
local events={os.pullEventRaw()}
if events[1]=='disk' then
if check(events[2])==password then
print('Keycard AcceptednOpening Door')
pulse(1,2)
else
print('Incorrect Keycard')
pulse(2,2)
end
disk.eject(events[2])
end
end