Posted 10 January 2013 - 05:56 AM
                Hello, a quick question/problem/error here.
I'm making a client/server based chat (I know, very original idea :)/>). In the client program, I have three functions:
one that receives messages from the server (getMessages), one that updates the screen (drawScreen) and one that gets user input (using the read() function) and sends the messages to the server (sendMessages). I then use the function parallel.waitForAny(getMessages,drawScreen,sendMessages) inside a while loop.
But when starting the program, I can't do anything, the screen keeps flickering and it exits after about 3-4 seconds with the error parallel:22 client:19: Too long without yielding
Simple question: how do I fix this?
By the way, should I post the code of the client program?
EDIT: I added the code
or
http://pastebin.com/MZ0uA2ZT
                
            I'm making a client/server based chat (I know, very original idea :)/>). In the client program, I have three functions:
one that receives messages from the server (getMessages), one that updates the screen (drawScreen) and one that gets user input (using the read() function) and sends the messages to the server (sendMessages). I then use the function parallel.waitForAny(getMessages,drawScreen,sendMessages) inside a while loop.
But when starting the program, I can't do anything, the screen keeps flickering and it exits after about 3-4 seconds with the error parallel:22 client:19: Too long without yielding
Simple question: how do I fix this?
EDIT: I added the code
Spoiler
--[[
chat system client
© 2013 InputUsername
please don't copy/redistribute/use this code
it's only here because I need to get an error fixed
]]
local chat = {"Welcome to chat!","Commands: /leave"}
local sLocalName, nServer
rednet.open("top")
local function getMessages()
  ev,id,msg = os.pullEvent("rednet_message")
  if id == nServer then
	msg = textutils.unserialize(msg)
	if not (msg == nil or msg["name"] == nil or msg["msg"] == nil) then
	  table.insert(chat,msg["name"].."> "..msg["msg"])
	end
  end
end
local function drawScreen()
  term.clear()
  term.setCursorPos(1,1)
  if #chat <= 16 then
	for i = 1, #chat do
	  print(chat[i])
	end
  else
	for i = #chat-17,#chat do
	  print(chat[i])
	end
  end
  term.setCursorPos(1,18)
  print(string.rep("-",52))
end
local function sendMessages()
  term.setCursorPos(1,19)
  term.clearLine()
  term.write("> ")
  local send = read()
  rednet.send(nServer,textutils.serialize({name=sLocalName,msg=send}))
end
term.clear()
term.setCursorPos(1,1)
print("Insert desired username:\n")
print("Insert server id to join:\n")
while (not sLocalName) or (not nServer) do
  term.setCursorPos(1,2)
  term.clearLine()
  sLocalName = read()
  term.setCursorPos(1,4)
  term.clearLine()
  nServer = tonumber(read())
  rednet.send(nServer,textutils.serialize({name=sLocalName,msg="/join"}))
  id,msg = rednet.receive(5)
  if id == nServer and msg then
	msg = textutils.unserialize(msg)
	if msg["name"] == "server" and msg["msg"] == "/ok" then
	  break
	elseif msg["name"] == "server" and msg["msg"] == "/double" then
	  sLocalName,nServer = nil,nil
	end
  else
	sLocalName,nServer = nil,nil
  end
end
while true do
  parallel.waitForAny(getMessages,drawScreen,sendMessages)
end
or
http://pastebin.com/MZ0uA2ZT
 
         
                 
                 
                