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

Help with code

Started by crazyjoe567, 30 January 2013 - 09:46 AM
crazyjoe567 #1
Posted 30 January 2013 - 10:46 AM
Im not sure why this isn't working so it would be really appreciated if someone could help me :)/>. Also on the console I get the message keycard:17: Invalid side. The program is called keycard by the way. He is the code:


password = "monkey"
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("down", true)
sleep(2)
rs.setOutput("down", false)
sleep(2)
rs.setOutput("down", true)
sleep(2)
rs.setOutput("down", false)
sleep(2)
rs.setOutput("down", true)
sleep(2)
rs.setOutput("down", false)
sleep(5)
rs.setOutput("left", true)
sleep(2)
rs.setOutput("left", false)
sleep(2)
rs.setOutput("left", true)
sleep(2)
rs.setOutput("left", false)
sleep(2)
rs.setOutput("left", true)
sleep(2)
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")


Then on a floppy disk I insert is called keycard and the Program is called keycard. On it, it only has the word monkey on it which normally works. The code I did before worked and only had

rs.setOutput("left", true)
sleep(5)
rs.setOutput("left", false)

instead of all of the multiple ones of it. Please help!
soccer16x #2
Posted 30 January 2013 - 10:48 AM
it should be "bottom" not "down", so all instances of "down" just need to be changed to "bottom"
TheOddByte #3
Posted 30 January 2013 - 10:55 AM
Well the side on line 17 was wrong

--Error
rs.setOutput("down", true)

--Solution
rs.setOutput("bottom", true)

EDIT: And Also If you use "up" or something that's also wrong since it needs to be "top"
By the way have you copy-pasted someone elses code since you did'nt know that?
crazyjoe567 #4
Posted 30 January 2013 - 11:09 AM
ah thanks
crazyjoe567 #5
Posted 30 January 2013 - 11:21 AM
Well the side on line 17 was wrong

--Error
rs.setOutput("down", true)

--Solution
rs.setOutput("bottom", true)

EDIT: And Also If you use "up" or something that's also wrong since it needs to be "top"
By the way have you copy-pasted someone elses code since you did'nt know that?
I haven't played with computercraft for a while so I forgot most of it