Jump to content




Need help with light program.


3 replies to this topic

#1 elliotjarnit

  • Members
  • 7 posts

Posted 11 April 2018 - 10: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


#2 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 12 April 2018 - 12:30 AM

remove the end after your elses

Edited by Lupus590, 12 April 2018 - 09:52 AM.


#3 Marc1miner

  • Members
  • 8 posts

Posted 12 April 2018 - 01: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 by Lyqyd, 12 April 2018 - 04:10 AM.


#4 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 12 April 2018 - 04:34 AM

View PostMarc1miner, on 12 April 2018 - 01:15 AM, said:

...
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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users