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

error

Started by LukaTech, 13 October 2014 - 10:57 PM
LukaTech #1
Posted 14 October 2014 - 12:57 AM
I am getting this error when i am attempting to run my program

bios:339: [string "ad"]:9: '<eof>' expected

My program displays certain messgaes if keywords are sent to it via rednet.


print("which room?  ")
local input, room = read("*")
room1 = "The " .. room .. "is "
lockdown = " WARNING The " .. room ..  " Has been Sealed "
print(" The room is now set to" .. room)
term.clear()
rednet.open("top")
end
while true do
local id, msg = rednet.receive()
if msg == "open"
  then term.setTextColor(colors.green)
  print(room1 .. msg)
  end
elseif msg == "Closed"
  then term.setTextColor(colors.yellow)
  print(room1 .. msg)
  end 
elseif msg == "clear"
then term.clear()
   end  
elseif msg == "lockdown"
then term.setTextColor(colors.red)
print(lockdown)
end
else end
Dragon53535 #2
Posted 14 October 2014 - 02:06 AM
You're code is not going to work by your uses of elseif and ends.

if x == 5 then
  --#do stuff
end
else --#Else what? As far as the program sees, there's nothing saying before to do, because your if's are ended and then do not allow more elses/elseif's
Edited on 14 October 2014 - 12:07 AM
Bomb Bloke #3
Posted 14 October 2014 - 03:41 AM
It's not just in relation to "if" statements that the "end"s are out of place - even the very first one shouldn't be there.

I recommend a read through this guide; also use this post as an example.

Edit:

To be specific, "eof" stands for "end of file". If you place an "end" statement which doesn't have a matching while/for/if/whatever block, the Lua interpreter will take that to mean the script should end at that point - so if there's any more code in the file, it'll assume you didn't mean to finish there and point out your mistake by throwing an error.
Edited on 14 October 2014 - 01:45 AM
Evil_Bengt #4
Posted 15 October 2014 - 08:05 AM
I tweaked it a little so it should work now:


print("which room?  ")
local input, room = read("*")
room1 = "The " .. room .. "is "
lockdown = " WARNING The " .. room ..  " Has been Sealed "
print(" The room is now set to" .. room)
term.clear()
rednet.open("top")
end
while true do
local id, msg = rednet.receive()
if msg == "open"
then term.setTextColor(colors.green)
print(room1 .. msg)
elseif msg == "Closed"
then term.setTextColor(colors.yellow)
print(room1 .. msg)
elseif msg == "clear" then
term.clear() 
elseif msg == "lockdown" then
term.setTextColor(colors.red)
print(lockdown)
end
Dragon53535 #5
Posted 15 October 2014 - 08:28 AM
Evil_Bengt
I tweaked it a little so it should work now:
–snip–

While helping out is fine in all regards, it's better to let them find the answer, or have them understand it, rather than give it outright. Why have one person coming back to AaP with a problem they're repeating when we could point out the error tell them how to fix it, and let them.

Also you're code is flawed, and didn't fix the original error.



print("which room?  ")
local input, room = read("*")
room1 = "The " .. room .. "is "
lockdown = " WARNING The " .. room ..  " Has been Sealed "
print(" The room is now set to" .. room)
term.clear()
rednet.open("top")
You've got a couple of problems with this first and foremost, your usage of read("*")
While that is correct, the way you're setting it to variables is wrong as read only returns a single variable so in the case of

local input,room = read("*")
input is whatever you type, and room is nil as there's nothing to set the value as.
Secondly, while i'm not sure that it's entirely wrong

room1 = "The " .. room .. "is "
should be

room1 = ("The " .. room .. "is ")
That way it knows that the whole thing is one part, and it makes sure that it's being set as that.


end
while true do
local id, msg = rednet.receive()
if msg == "open"
  then term.setTextColor(colors.green)
  print(room1 .. msg)
  end
elseif msg == "Closed"
  then term.setTextColor(colors.yellow)
  print(room1 .. msg)
  end
elseif msg == "clear"
then term.clear()
   end
elseif msg == "lockdown"
then term.setTextColor(colors.red)
print(lockdown)
end
else end
There are many problems here and we pointed the most glaring one out, the one with your if's and elseif's however the one that's causing your error that you see, is the first line in this section. There's nothing to end, and so it's raising that error.

Now if you incorporate all that advice into a file you should get something like this
Spoiler

print("which room?  ")
local room = read("*")
room1 = ("The " .. room .. "is ")
lockdown = (" WARNING The " .. room ..  " Has been Sealed ")
print(" The room is now set to" .. room)
term.clear()
rednet.open("top")
while true do
  local id, msg = rednet.receive()
  if msg == "open" then
	term.setTextColor(colors.green)
	print(room1 .. msg)
  elseif msg == "Closed" then
	term.setTextColor(colors.yellow)
	print(room1 .. msg)
  elseif msg == "clear" then
	term.clear()
  elseif msg == "lockdown" then
	term.setTextColor(colors.red)
	print(lockdown)
  end
end

Edit: Thanks for pointing that out Bengt
Edited on 23 October 2014 - 12:07 PM
Evil_Bengt #6
Posted 23 October 2014 - 07:07 AM
Evil_Bengt
I tweaked it a little so it should work now:
–snip–

While helping out is fine in all regards, it's better to let them find the answer, or have them understand it, rather than give it outright. Why have one person coming back to AaP with a problem they're repeating when we could point out the error tell them how to fix it, and let them.

Also you're code is flawed, and didn't fix the original error.



print("which room?  ")
local input, room = read("*")
room1 = "The " .. room .. "is "
lockdown = " WARNING The " .. room ..  " Has been Sealed "
print(" The room is now set to" .. room)
term.clear()
rednet.open("top")
You've got a couple of problems with this first and foremost, your usage of read("*")
While that is correct, the way you're setting it to variables is wrong as read only returns a single variable so in the case of

local input,room = read("*")
input is whatever you type, and room is nil as there's nothing to set the value as.
Secondly, while i'm not sure that it's entirely wrong

room1 = "The " .. room .. "is "
should be

room1 = ("The " .. room .. "is ")
That way it knows that the whole thing is one part, and it makes sure that it's being set as that.


end
while true do
local id, msg = rednet.receive()
if msg == "open"
  then term.setTextColor(colors.green)
  print(room1 .. msg)
  end
elseif msg == "Closed"
  then term.setTextColor(colors.yellow)
  print(room1 .. msg)
  end
elseif msg == "clear"
then term.clear()
   end
elseif msg == "lockdown"
then term.setTextColor(colors.red)
print(lockdown)
end
else end
There are many problems here and we pointed the most glaring one out, the one with your if's and elseif's however the one that's causing your error that you see, is the first line in this section. There's nothing to end, and so it's raising that error.

Now if you incorporate all that advice into a file you should get something like this
Spoiler

print("which room?  ")
local, room = read("*")
room1 = ("The " .. room .. "is ")
lockdown = (" WARNING The " .. room ..  " Has been Sealed ")
print(" The room is now set to" .. room)
term.clear()
rednet.open("top")
while true do
  local id, msg = rednet.receive()
  if msg == "open" then
	term.setTextColor(colors.green)
	print(room1 .. msg)
  elseif msg == "Closed" then
	term.setTextColor(colors.yellow)
	print(room1 .. msg)
  elseif msg == "clear" then
	term.clear()
  elseif msg == "lockdown" then
	term.setTextColor(colors.red)
	print(lockdown)
  end
end

Oh, I was probably to tired, and personally I think it's easier to learn when I see command in a code and see how they work and how they behave, ofcourse people is different…
And just a small thing that may not get noticed:

There's a comma in line 2 that may screw things up :D/>