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

[Lua][Error] <eof> expected?

Started by cammygames, 22 April 2012 - 02:11 PM
cammygames #1
Posted 22 April 2012 - 04:11 PM
Before i begin i did not write the bulk of the code it is an adaptation of ComputerCraftFan11's irc program

When i try to run this i get this error
bios:206: [string "irc"]:106: '<eof>' expected

here is the code
Spoiler

rednet.open("top")
local sFile, sName = "ops.txt", ""
local channel = "";
local user = "";
local ip = os.computerID()
local channelID = 0;
local chatHistory = ""
local messages = 4;
local opmode = false;
local kkmode = false;
local isChatter = false;
local deopmode = false;
local oldUser = ""
--------------------------------------------------
local function cPrint(text)
   local x,y = term.getSize()
   x2,y2 = term.getCursorPos()
   term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
   write(text)
end
--------------------------------------------------
--------------------------------------------------
term.clear()
term.setCursorPos(1,1)
-----------------------------------------------------
function status()
   print("Status: " ..channel)
   print("--------------------------------")
end
-----------------------------------------------------
-----------------------------------------------------
function getops()
	    if fs.exists(sFile) then
			    local hRead = assert(fs.open(sFile, "r"))
			    sName = hRead.readLine()
			    hRead.close()
	    else
			    print("Creating file")
  io.open("sFile", "w"):close()
	    end
end
-----------------------------------------------------
-----------------------------------------------------
function chatbox()
   term.clear()
   term.setCursorPos(1,1)
   status()
   print("[" ..channel.. "] "..user.." joined the server!")
   term.setCursorPos(1, sizeY)
   term.setCursorBlink( true )
   while true do
	  local e, pie, test = os.pullEvent()
	  if e == "rednet_message" then
		 if test == "pinged " ..channel then
		    rednet.send(pie, "chatbox")
		 else
					    if(test == "["..channel.."] /op " ..user)then
							    oldUser = user
							    user = "@" .. user
							    isChatter = true
    if os.computerID() == 1473 then
							    fsfile.writeLine(cammy)
							    hWrite.close()
							    end
			    rednet.broadcast("*" ..user.. " is now OP!")
			    term.setCursorPos(1, messages)
			    messages = messages +1
			    print("You are now OP!")
							  
					    elseif(test == "["..channel.."] /deop " ..user)then
			    rednet.broadcast("*" ..user.. " is no longer OP!")
							    user = oldUser
							    isChatter = false
			    term.setCursorPos(1, messages)
			    messages = messages +1
			    print("You are no longer OP!")
					    elseif(test == "["..channel.."] /kick " ..user)then
			    rednet.broadcast("*" ..user.. " left.")
							    menu()
					    elseif(test == "["..channel.."] /ls")then
			    rednet.send(pie, "[List:] " ..user)
					    end
		    local x,y = term.getSize()
		    if messages < y then
			   term.setCursorPos(1, messages)
			   messages = messages +1
			   print(test)
		    else
			   term.clear()
			   term.setCursorPos(1,1)
			   status()
			   messages = 3
			   term.setCursorPos(1, messages)
			   messages = messages +1
			   print("test")
		    end
		 end
	  end
  end
end
elseif e == "char" then
		 local x,y = term.getSize()
		 term.setCursorPos(1,1)
		 chatHistory = chatHistory.. "" ..pie
		 term.clearLine()
		 write(chatHistory)
	  elseif e == "key" and pie == 28 or pie == 14 then
		 if pie == 28 then
		    if chatHistory == "/exit" then
			   rednet.broadcast("*" ..user.. " left.")
			   chatHistory = ""
			   menu()
		    elseif chatHistory == "/ping" then
				  term.setCursorPos(1, messages)
				  messages = messages +1
				  print("[" ..channel.. "] Pong")
		    elseif chatHistory == "/help" then
				  term.setCursorPos(1, messages)
				  messages = messages +1
								  if isChatter == true then
									    print("[" ..channel.. "] Commands: /help, /ping, /exit, /op, /kick, /ls")
								  else
								    print("[" ..channel.. "] Commands: /help, /ping, /exit, /ls")
								  end
		    else
			   if isChatter == true then
							  if opmode == true then
								    rednet.broadcast("["..channel.."] " ..chatHistory)
				    term.setCursorPos(1, messages)
				    messages = messages +1
				    print("["..channel.."] " ..chatHistory)
								  elseif kkmode == true then
								    rednet.broadcast("["..channel.."] " ..chatHistory)
				    term.setCursorPos(1, messages)
				    messages = messages +1
				    print("["..channel.."] " ..chatHistory)
								  elseif deopmode == true then
								    rednet.broadcast("["..channel.."] " ..chatHistory)
				    term.setCursorPos(1, messages)
				    messages = messages +1
				    print("["..channel.."] " ..chatHistory)
								  else
								    rednet.broadcast("[" ..user.. "] " ..chatHistory)
				    term.setCursorPos(1, messages)
				    messages = messages +1
				    print("[" ..user.. "] " ..chatHistory)
								  end
			   else
				 rednet.broadcast("<" ..user.. "> " ..chatHistory)
				 term.setCursorPos(1, messages)
				 messages = messages +1
				 print("<" ..user.. "> " ..chatHistory)
			   end
		    end
		 end
				 if chatHistory == "/ls" then
				 term.setCursorPos(1, messages)
				 messages = messages +1
				 print("[List:] " ..user)
				 rednet.broadcast("["..channel.."] /ls")
				 end
		 chatHistory = ""
		 local x,y = term.getSize()
		 term.setCursorPos(1, y)
		 term.clearLine()
				 opmode = false
				 kkmode = false
				 deopmode = false
		  elseif e == "key" and pie == 57 then
			    if chatHistory == "/op" or chatHistory == "/op " then
					    opmode = true
			    elseif chatHistory == "/kick" or chatHistory == "/kick " then
					    kkmode = true
			    elseif chatHistory == "/deop" or chatHistory == "/deop " then
					    deopmode = true
			    end
	  end
   end
end
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
function connector()
   term.clear()
   term.setCursorPos(1,1)
   status()
   print("Logging in...")
   print(user.. " ["..ip.."] logged in to MJ-IRC!")
   print("Connecting to " ..channel.."...")
   rednet.broadcast("pinged " ..channel)
   id, message = rednet.receive(1)
   if message == "chatbox" then
	  print("Connected! Joining...")
	  rednet.broadcast("[" ..channel.. "] "..user.." joined the server!")
	  sleep(0.5)
	  channelID = id
	  chatbox()
   else
	  print("Server Does Not Exist... Hosting")
	  print("Connected! Joining...")
	  isChatter = true
	  user = "@" ..user
	  rednet.broadcast("[" ..channel.. "] "..user.." joined the server!")
	  sleep(0.5)
	  channelID = id
	  chatbox()
   end
   if os.computerID() == 1473 then
					    oldUser = user
					    user = "@" .. user
					    isChatter = true
else
		 break
   
   end
  
  
  
end
-----------------------------------------------
-----------------------------------------------
function login()
   term.clear()
   term.setCursorPos(1,1)
   cPrint("NeXuS IRC \n")
   cPrint("Nickname: ")
   nick = read()
   cPrint("Channel: #")
   chan = read()
  
   channel = "#" ..chan
   user = nick
   connector()
end
-----------------------------------------------
-----------------------------------------------
function menu()
   term.clear()
   term.setCursorPos(1,1)
   cPrint("MJ IRC \n \n")
   cPrint("1:) Login\n")
   cPrint("2:) Exit \n \n")
   cPrint("Selection: ")
   input = read()
   if input == "1" then
	  login()
   elseif input == "2" then
   else
	  menu()
   end
end

menu()

if you are wondering what i have added before you have read the code i have attempted to make an auto op system so if youre oped it saves it and when you join it re ops you

hope you can help
Teraminer #2
Posted 22 April 2012 - 04:26 PM
You need to remove the end from line 106.
cammygames #3
Posted 22 April 2012 - 06:19 PM
sry that would work would it because the line is

elseif e == "char" then
cammygames #4
Posted 22 April 2012 - 09:57 PM
ok im wont be arround for a week so a freind of mine might try to answer on my behalf and fix the code
Luanub #5
Posted 22 April 2012 - 11:18 PM
There were 3 extra ends and some if statement logic in the chatbox function. I haven't tested it but I corrected both of those errors. Here is the corrected function.

Spoiler

function chatbox()
   term.clear()
   term.setCursorPos(1,1)
   status()
   print("[" ..channel.. "] "..user.." joined the server!")
   term.setCursorPos(1, sizeY)
   term.setCursorBlink( true )
   while true do
    local e, pie, test = os.pullEvent()
    if e == "rednet_message" then
        if test == "pinged " ..channel then
            rednet.send(pie, "chatbox")
        else
            if(test == "["..channel.."] /op " ..user)then
                oldUser = user
                user = "@" .. user
                isChatter = true
                if os.computerID() == 1473 then
                    fsfile.writeLine(cammy)
                    hWrite.close()
                end
                rednet.broadcast("*" ..user.. " is now OP!")
                term.setCursorPos(1, messages)
                messages = messages +1
                print("You are now OP!")
            elseif(test == "["..channel.."] /deop " ..user)then
                rednet.broadcast("*" ..user.. " is no longer OP!")
                user = oldUser
                isChatter = false
                term.setCursorPos(1, messages)
                messages = messages +1
                print("You are no longer OP!")
            elseif(test == "["..channel.."] /kick " ..user)then
                rednet.broadcast("*" ..user.. " left.")
                menu()
            elseif(test == "["..channel.."] /ls")then
                rednet.send(pie, "[List:] " ..user)
            end
            local x,y = term.getSize()
            if messages < y then
                term.setCursorPos(1, messages)
                messages = messages +1
                print(test)
            else
                term.clear()
                term.setCursorPos(1,1)
                status()
                messages = 3
                term.setCursorPos(1, messages)
                messages = messages +1
                print("test")
            end
        end
    elseif e == "char" then
        local x,y = term.getSize()
        term.setCursorPos(1,1)
        chatHistory = chatHistory.. "" ..pie
        term.clearLine()
        write(chatHistory)
    elseif e == "key" and pie == 28 or pie == 14 then
        if pie == 28 then
            if chatHistory == "/exit" then
                rednet.broadcast("*" ..user.. " left.")
                chatHistory = ""
                menu()
            elseif chatHistory == "/ping" then
                term.setCursorPos(1, messages)
                messages = messages +1
                print("[" ..channel.. "] Pong")
            elseif chatHistory == "/help" then
                term.setCursorPos(1, messages)
                messages = messages +1
                if isChatter == true then
                    print("[" ..channel.. "] Commands: /help, /ping, /exit, /op, /kick, /ls")
                else
                    print("[" ..channel.. "] Commands: /help, /ping, /exit, /ls")
                end
            else
                if isChatter == true then
                    if opmode == true then
                        rednet.broadcast("["..channel.."] " ..chatHistory)
                        term.setCursorPos(1, messages)
                        messages = messages +1
                        print("["..channel.."] " ..chatHistory)
                    elseif kkmode == true then
                        rednet.broadcast("["..channel.."] " ..chatHistory)
                        term.setCursorPos(1, messages)
                        messages = messages +1
                        print("["..channel.."] " ..chatHistory)
                    elseif deopmode == true then
                        rednet.broadcast("["..channel.."] " ..chatHistory)
                        term.setCursorPos(1, messages)
                        messages = messages +1
                        print("["..channel.."] " ..chatHistory)
                    else
                        rednet.broadcast("[" ..user.. "] " ..chatHistory)
                        term.setCursorPos(1, messages)
                        messages = messages +1
                        print("[" ..user.. "] " ..chatHistory)
                    end
                end
            end
        else
            rednet.broadcast("<" ..user.. "> " ..chatHistory)
            term.setCursorPos(1, messages)
            messages = messages +1
            print("<" ..user.. "> " ..chatHistory)
        end
        if chatHistory == "/ls" then
            term.setCursorPos(1, messages)
            messages = messages +1
            print("[List:] " ..user)
            rednet.broadcast("["..channel.."] /ls")
        end
        chatHistory = ""
        local x,y = term.getSize()
        term.setCursorPos(1, y)
        term.clearLine()
        opmode = false
        kkmode = false
        deopmode = false
    elseif e == "key" and pie == 57 then
        if chatHistory == "/op" or chatHistory == "/op " then
            opmode = true
        elseif chatHistory == "/kick" or chatHistory == "/kick " then
            kkmode = true
        elseif chatHistory == "/deop" or chatHistory == "/deop " then
            deopmode = true
        end
    end
end
end
cammygames #6
Posted 23 April 2012 - 10:22 AM
thankz but now it automatically op's every one can u maybe point iut where i have gon wrong
Luanub #7
Posted 23 April 2012 - 11:03 AM
Try changing the following, its in the there a couple of times


--change
if(test == "["..channel.."] /op " ..user)then

--to
if test == ("["..channel.."] /op " ..user) then

You can also print out the message so you can verify what is being sent, that way you can verify the code is handling what it is receiving correctly.


local e, pie, test = os.pullEvent()
    if e == "rednet_message" then
	    if test == "pinged " ..channel then
		    rednet.send(pie, "chatbox")
	    else
        print (pie) -- add in this
        print (test) -- and this
        sleep(2) -- and this so you have time to read it
Edited on 23 April 2012 - 09:08 AM
cammygames #8
Posted 26 April 2012 - 05:49 PM
so would this be right


Spoilerfunction chatbox()
term.clear()
term.setCursorPos(1,1)
status()
print("[" ..channel.. "] "..user.." joined the server!")
term.setCursorPos(1,18)
term.setCursorBlink( true )
while true do
local e, pie, test = os.pullEvent()
if e == "rednet_message" then
if test == "pinged " ..channel then
rednet.send(pie, "chatbox")
elseif test == ("["..channel.."] /deop " ..user)then
rednet.broadcast("*" ..user.. " is no longer OP!")
user = oldUser
isChatter = false
term.setCursorPos(1, messages)
messages = messages +1
print("You are no longer OP!")
elseif test == ("["..channel.."] /kick " ..user)then
rednet.broadcast("*" ..user.. " left.")
menu()
elseif test == ("["..channel.."] /ls")then
rednet.send(pie, "[List:] " ..user)
else
print (pie)
print (test)
sleep(2)
end
local x,y = term.getSize()
if messages < y then
term.setCursorPos(1, messages)
messages = messages +1
print(test)
else
term.clear()
term.setCursorPos(1,1)
status()
messages = 3
term.setCursorPos(1, messages)
messages = messages +1
print ("test")
end
end
elseif e == "char" then
local x,y = term.getSize()
term.setCursorPos(1,1)
chatHistory = chatHistory.. "" ..pie
term.clearLine()
write(chatHistory)
elseif e == "key" and pie == 28 or pie == 14 then
if pie == 28 then
if chatHistory == "/exit" then
rednet.broadcast("*" ..user.. " left.")
chatHistory = ""
menu()
elseif chatHistory == "/ping" then
term.setCursorPos(1, messages)
messages = messages +1
print("[" ..channel.. "] Pong")
elseif chatHistory == "/help" then
term.setCursorPos(1, messages)
messages = messages +1
if isChatter == true then
print("[" ..channel.. "] Commands: /help, /ping, /exit, /op, /kick, /ls")
else
print("[" ..channel.. "] Commands: /help, /ping, /exit, /ls")
end
else
if isChatter == true then
if opmode == true then
rednet.broadcast("["..channel.."] " ..chatHistory)
term.setCursorPos(1, messages)
messages = messages +1
print("["..channel.."] " ..chatHistory)
elseif kkmode == true then
rednet.broadcast("["..channel.."] " ..chatHistory)
term.setCursorPos(1, messages)
messages = messages +1
print("["..channel.."] " ..chatHistory)
elseif deopmode == true then
rednet.broadcast("["..channel.."] " ..chatHistory)
term.setCursorPos(1, messages)
messages = messages +1
print("["..channel.."] " ..chatHistory)
else
rednet.broadcast("[" ..user.. "] " ..chatHistory)
term.setCursorPos(1, messages)
messages = messages +1
print("[" ..user.. "] " ..chatHistory)
end
end
end
else
rednet.broadcast("<" ..user.. "> " ..chatHistory)
term.setCursorPos(1, messages)
messages = messages +1
print("<" ..user.. "> " ..chatHistory)
end
if chatHistory == "/ls" then
term.setCursorPos(1, messages)
messages = messages +1
print("[List:] " ..user)
rednet.broadcast("["..channel.."] /ls")
end
chatHistory = ""
local x,y = term.getSize()
term.setCursorPos(1, y)
term.clearLine()
opmode = false
kkmode = false
deopmode = false
elseif e == "key" and pie == 57 then
if chatHistory == "/op" or chatHistory == "/op " then
opmode = true
elseif chatHistory == "/kick" or chatHistory == "/kick " then
kkmode = true
elseif chatHistory == "/deop" or chatHistory == "/deop " then
deopmode = true
end
end
end
end
Edited on 26 April 2012 - 03:51 PM
libraryaddict #9
Posted 26 April 2012 - 06:27 PM
Its still not right.
try formatting.
Eg
function DirX(dir)
 if dir == 1 then --Left
  return -1
 elseif dir == 2 then --Right
  return 1
 elseif dir == 3 or dir == 4 then
  return 0
 else
  error("funtion Direction was handled incorrectly")
 end
end

You can see problems easier
cammygames #10
Posted 26 April 2012 - 07:41 PM
like this https://github.com/cammygames/lua/blob/master/startup
libraryaddict #11
Posted 26 April 2012 - 08:20 PM
You dont see the 2nd end at line 185?