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

eof expected?

Started by deity12, 15 May 2012 - 06:56 AM
deity12 #1
Posted 15 May 2012 - 08:56 AM
Ok so I'm trying to creating a password code door that locks you out of the system(well it sleeps) for 30 secs after you get the code wrong 3 times.
I keep getting this error(it's different if I change around the ends but I still cant fix it)
bios:206: [string "startup"]:15: '<eof>' expected

Can someone please find the fault in my coding I've been trying for at least an hour myself(I'm very new to lua)
Here is my coding:



function pass()
shell.run("clear")
print ("Please enter password here:")
t = read("*")
if t == "password" then
print ("Password Correct!")
redstone.setOutput("left", true)
sleep(3)
redstone.setOutput("left", false)
shell.run("clear")
pass()
end
end
pass()
else
print ("Password Incorrect. Two attempts reamaining.")
sleep(2)
t = read("*")
if t == "password" then
print ("Password Correct!")
redstone.setOutput("left", true)
sleep(3)
redstone.setOutput("left", false)
shell.run("clear")
pass()
end
end
pass()
else
print ("Password Incorrect. One attempt remaining.")
sleep(2)
t = read("*")
if t == "password" then
print ("Password Correct!")
redstone.setOutput("left", true)
sleep(3)
redstone.setOutput("left", false)
shell.run("clear")
pass()
end
end
pass()
else
print ("Password Incorrect. Locking for 30 seconds.")
sleep(10)
print ("Unlocking in 20 seconds.")
sleep(10)
print ("Unlocking in 10 seconds.")
sleep(10)
print ("Console unlocked.")
sleep(2)
shell.run("clear")
pass()
end
end
pass()
Luanub #2
Posted 15 May 2012 - 09:31 AM
Your if syntax is incorrect and you have way to many ends.

To do an if statement with an else it should look something like, notice only 1 end and its after the else.

if a == "b" then
    do some stuff
else
   do other stuff
end

so its,
if do stuff end
or if do stuff else do other stuff end
or if do stuff elseif do something different else do other stuff end.
my_hat_stinks #3
Posted 15 May 2012 - 12:38 PM
Use coding best practices please, a wall of code is near impossible to debug

function pass()
   shell.run("clear")
   print ("Please enter password here:")
   t = read("*")
   if t == "password" then
	  print ("Password Correct!")
	  redstone.setOutput("left", true)

	  sleep(3)
	  redstone.setOutput("left", false)

	  shell.run("clear")
	  pass()
   end
end

pass()
else  --//****Doesn't fit here!****
print ("Password Incorrect. Two attempts reamaining.")
sleep(2)
t = read("*")
if t == "password" then
   print ("Password Correct!")
   redstone.setOutput("left", true)

   sleep(3)
   redstone.setOutput("left", false)

   shell.run("clear")
   pass()
end
end  --//****Doesn't fit here!****
pass()
else  --//****Doesn't fit here!****
print ("Password Incorrect. One attempt remaining.")
sleep(2)
t = read("*")
if t == "password" then
   print ("Password Correct!")
   redstone.setOutput("left", true)

   sleep(3)
   redstone.setOutput("left", false)

   shell.run("clear")
   pass()
end
end  --//****Doesn't fit here!****
pass()
else  --//****Doesn't fit here!****
print ("Password Incorrect. Locking for 30 seconds.")
sleep(10)

print ("Unlocking in 20 seconds.")
sleep(10)

print ("Unlocking in 10 seconds.")
sleep(10)

print ("Console unlocked.")
sleep(2)

shell.run("clear")
pass()

end  --//****Doesn't fit here!****
end  --//****Doesn't fit here!****
pass()

With proper indentation, these errors are incredibly easy to spot
MathManiac #4
Posted 17 May 2012 - 04:07 AM
Use coding best practices please, a wall of code is near impossible to debug

–snip–

Boy, I totally agree!