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")
[/font][/color]
Need Help With Redstone Outputs
Started by cheekycharlie101, Aug 31 2012 09:29 AM
7 replies to this topic
#1
Posted 31 August 2012 - 09: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:
#2
Posted 31 August 2012 - 11:25 AM
Help pleaseee
#3
Posted 31 August 2012 - 03: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
#4
Posted 01 September 2012 - 01:46 PM
Kolpa, on 31 August 2012 - 03:56 PM, said:
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
#5
Posted 01 September 2012 - 02:13 PM
Kolpa, on 31 August 2012 - 03:56 PM, said:
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.
#6
Posted 02 September 2012 - 02:49 PM
i fixed my code after finally getting mc back to working -.-
was missing some end's this should work
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
#7
Posted 03 September 2012 - 01:34 PM
Kolpa, on 02 September 2012 - 02:49 PM, said:
i fixed my code after finally getting mc back to working -.-
was missing some end's this should work
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
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
.
#8
Posted 03 September 2012 - 02: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
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











