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

Need help with light program.

Started by elliotjarnit, 11 April 2018 - 09:51 PM
elliotjarnit #1
Posted 11 April 2018 - 11:51 PM
Im building a underground base with a light system. When you go inside the base to turn on the lights(and all the other computers) u have to write in the password. I keep getting the error <eof> expected. Please help! i can also show u the lightson script.
Heres the startup:

local password = "elliot9999" -- Change this to what you want your password to be.
local oldPull = os.pullEventRaw
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.lightBlue)
print("Please enter password to activate base.")
term.setTextColor(colors.yellow)
write("> ")
term.setTextColor(colors.gray)
local input = read("*")
if input == password then
term.clear()
term.setCursorPos(1,1)
  term.setTextColor(colors.lime)
  print("Welcome back, TheBeast99100")
  sleep(2)
  term.clear()
  term.setCursorPos(1,1)
  shell.run("/lightson")
  rs.setOutput("back", true)
  end
  else
  term.setTextColor(colors.red)
  term.clear()
  term.setCursorPos(1,1)
  print("Access Denied.")
  sleep(1)
  term.clear()
  term.setCursorPos(1,1)
  end
os.pullEvent = oldPull
and the lightson script

term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.purple)
print("Press enter to shutdown base")
input = io.read()
if input == "" then
rs.setOutput("back", false)
os.reboot()
end
else
rs.setOutput("back", false)
os.reboot()
end
Lupus590 #2
Posted 12 April 2018 - 01:30 AM
remove the end after your elses
Edited on 12 April 2018 - 08:52 AM
Marc1miner #3
Posted 12 April 2018 - 02:15 AM
First of all, you should spend more time in making your code more readable. You can do this by using indentation.
Example:


local password = "123"
local input = read("*")

if input == password then
	 print("correct")
else
	 print("incorrect")
end

anyway, I see a few mistakes already.

1. in your startup file you call two functions os.pullEvent() and os.pullRawEvent(), but you forgot the ( ), which likely caused the <eof> error.
2. you do an if-else construction, however you close the if-statement with end before you type else, to fix this remember that all if-else statements are contructed like this
Edited on 12 April 2018 - 03:10 AM
Dog #4
Posted 12 April 2018 - 05:34 AM

1. in your startup file you call two functions os.pullEvent() and os.pullRawEvent(), but you forgot the ( ), which likely caused the <eof> error.
2. you do an if-else construction, however you close the if-statement with end before you type else, to fix this remember that all if-else statements are contructed like this

Number one is not an issue as elliotjarnit is not calling os.pullEvent or os.pullEventRaw, he is setting them up so that os.pullEventRaw is called by default instead of os.pullEvent. This would have nothing at all to do with an <eof> error.

Number two is what is causing the <eof> error, as already pointed out by Lupus590.

Simply remove the end statements right before the elseif statements and that will eliminate the <eof> errors. In Lua, the end keyword closes an if/elseif/else statement - if valid code is not found after the end keyword, the interpreter assumes it has reached the intended end of the file and reports that <eof> (end of file) is expected. Since no conditional starts with elseif, the remaining code after the first end keyword is considered invalid and <eof> is expected. The will happen in both your startup and lightson scripts as they both have the same code error.