Posted 25 November 2013 - 12:42 PM
I've been working on a chat system which works with Rednet and the actual chat bit works fine. My problem is, after about 10 or so messages, the screen runs out of room. I've made a very basic scrolling system which is extremely buggy (1 message will show, then nothing will, and then a large line will show) and I don't really know what to do any more.
Here is all my code so far:
Here is all my code so far:
term.clear()
term.setCursorPos(1,1)
lastMsg = 0
rednet.open("top")
write("Enter the ID of your chatting partner: ")
id = tonumber(read())
write("Enter their name too: ")
name = read()
term.clear()
term.setCursorPos(1,1)
local rMsg = ""
local sMsg = ""
function gui()
width, height = term.getSize()
term.setCursorPos(1, height - 3)
term.setTextColor(colors.white)
for i=1, width do
write("-")
end
end
function display(isReceived)
if isReceived == true then
nametag = name
else
nametag = "You"
end
term.setCursorPos(1, lastMsg+1)
x, y = term.getCursorPos()
if y == height-5 then
term.scroll(1)
term.setCursorPos(1, height-5)
term.clearLine()
end
term.setTextColor(colors.red)
if sMsg ~= "" then
write("[" .. nametag .. "]")
term.setTextColor(colors.lime)
if isReceived == true then
write(rMsg)
else
write(sMsg)
end
if lastMsg < height-4 then
lastMsg = lastMsg + 1
else
lastMsg = height-6
end
end
end
function send()
term.setTextColor(colors.red)
write("Message: ")
term.setTextColor(colors.white)
sMsg = read()
rednet.send(id, sMsg)
display(false)
end
function receive()
id, rMsg = rednet.receive()
display(true)
end
gui()
while true do
gui()
parallel.waitForAny(send, receive)
term.setCursorPos(1, height - 2)
term.clearLine()
term.setCursorPos(1, height - 1)
term.clearLine()
term.setCursorPos(1, height)
term.clearLine()
end