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

Stupid Unexpected Symbol Error

Started by Jack423, 22 March 2014 - 04:58 PM
Jack423 #1
Posted 22 March 2014 - 05:58 PM
I made a program to check the floppy disk for "door1" on the card for the "password". it was working before but I must have accidentally changed something and I can't figure it out. here is my code…

password = “door1”
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")

If you can help me solve this problem that would be great.
CometWolf #2
Posted 22 March 2014 - 08:23 PM
Oh my what an ugly piece of code. USE CODE TAGS!
This topic is titled "Read This Post Before Asking Questions" for a reason…
http://www.computerc...king-questions/
Reading it should also tell you to give us the entire error message. The number is not something random, and should not be left out.
Edited on 22 March 2014 - 07:23 PM
CastleMan2000 #3
Posted 21 April 2014 - 08:06 PM
I just quickly looked at it, but I think file:read() should be file:readAll(). I could be wrong.
Lyqyd #4
Posted 21 April 2014 - 08:27 PM
You are indeed wrong. Handle:read() is used with io-opened file handles, while handle.readAll() is used with fs-opened file handles.
CastleMan2000 #5
Posted 21 April 2014 - 08:33 PM
Okay. I don't use io very often, thank you for the correction.
CometWolf #6
Posted 21 April 2014 - 09:10 PM
The error is the result of his weird string declaration lol.

“door1”
Chances are this guy is long gone though, so probably dosen't matter :P/>
Edited on 21 April 2014 - 07:12 PM