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

[Lua] [Error] <eof> expected

Started by Masoman3, 08 July 2012 - 03:14 AM
Masoman3 #1
Posted 08 July 2012 - 05:14 AM
Just some background first:
I was messing around with the rednet stuff, creating linked computers that would send and receive info, the basic idea was to see if I could get a main computer to send a message to multiple computers, triggering the receiving one to send back a message, of whether or not there was a current flowing into a selected side. As such, there was two separate bits of code, and I will post both. I also tried to get it to display to a monitor, using a startup program that called [ shell.run("monitor", "top", "startup_prog")]. However, I could run it both ways.

The Error:
When I try to run the program, I get an error that says:
[indent=1][bios:206: [string "startup_prog"]:77: '<eof>' expected][/indent]
I believe that <eof> is the end of file marker, and to fix this I tried opening the actual file in about 3 different programs, namely notepad and notepad++. However, it gave me another error saying there was an unexpected symbol on line 77.

Help?

Main server code:
[attachment=295:startup_prog-main.txt]

Client code:
[attachment=294:startup_prog-client.txt]
ardera #2
Posted 08 July 2012 - 05:52 AM
I believe that <eof> is the end of file marker
<eof> is not end of File!
its needed for else's and elseif's that are not needed… Example:

if ok then
  print("ok")
end
else
  print("not ok")
end

PS.: The error said: string["startup_prog"] so what program is the right? startup_prog-main or startup_prog-client?
Masoman3 #3
Posted 08 July 2012 - 06:05 AM
The client code works fine, the main server one is the one showing the error. Also, end of file is just what I remembered from some c++ tutorials, with reading in files.
ardera #4
Posted 08 July 2012 - 06:15 AM
You had one end to much, here is the corrected code, i think it will work:
(i dont know how to upload attachments, so here is the code:)
Spoiler


--Variables
local side
local inputSide
local noSys
local systemIds = {}
local id
local isChecked
local message
local event
local RedstoneInput

term.setCursorPos(1,1) -- Fixes the cursor position
term.clear()
write ("Please enter side of Input: ")
inputSide = read()
write ("Please enter side of Modem: ")
side = read()
write("nPlease enter the amount of systems to check: ")
noSys = read()
noSys = tonumber(noSys)
if (noSys <= 0) then
write ("nToo few systems, program restarting n")
else 
write("nPlease enter the ID's of the systems nFirst ID: " )
for i = 1, noSys do
id = read()
id = tonumber(id)
table.insert(systemIds, i, id)
if ( i ~= noSys) then 
write("nNext ID: ")
end
end
end
while true do
term.setCursorPos(1,1) -- Fixes the cursor position
term.clear()
RedstoneInput = false
while (RedstoneInput ~= true) do
write ("nChecking for Begin Checking redstone input")
RedstoneInput = rs.getInput(inputSide)
sleep(3)
end
rs.setOutput("bottom", true)
sleep (2)
rs.setOutput("bottom", false)
if (RedstoneInput == true) then
rednet.open(side)
write("|-----------------------------------------------|n")
for i = 1, noSys do
isChecked = false
while (isChecked == false) do
rednet.send(systemIds[i], "Check System")
write("nSent Check System to ".. systemIds[i] .. "n")
write ("Testing ".. systemIds[i])
id, message = rednet.receive(2)
write ("nChecked for messagen")
if (id == systemIds[i]) then
isChecked = true
rednet.send(systemIds[i], "received")
write ("Sent recieved to client")
write("n".. message)
end
end
sleep(3)
write ("|-----------------------------------------------|n")
end
rednet.close(side)
write ("nPress any key to continue")
while true do
local sEvent = os.pullEvent("key")
if (sEvent == "key") then
break
end
end
end
end
Masoman3 #5
Posted 08 July 2012 - 06:40 AM
Thankyou, Its working now. BTW, did you like the idea?
ardera #6
Posted 08 July 2012 - 09:12 AM
if you mean the program: don't know what it's for but look good.
Lyqyd #7
Posted 08 July 2012 - 08:45 PM
I believe that <eof> is the end of file marker
<eof> is not end of File!
its needed for else's and elseif's that are not needed… Example:

if ok then
  print("ok")
end
else
  print("not ok")
end

PS.: The error said: string["startup_prog"] so what program is the right? startup_prog-main or startup_prog-client?

<eof> absolutely is the end-of-file marker.

This error code is a symptom of having extra 'end' statements. Also, what are you trying to show in your example? There are too many end statements there too.