Posted 28 August 2013 - 10:55 PM
I'm trying to make a irc-like chat program, but this code just freezes the computer- it doesn't even clear the screen.
edit: updated code - still freezing
Here is the code:
If you could help me that would be awesome! Thanks.
Edit: Typo in the code… didn't stop the freezing though. Neither did opening the side (though it should at least tell me that was wrong..?). If you press hyphen weird stuff happens, code sometimes clears and stuff like that. Though the program never stops when hyphen is pressed.
Edit2: The program does crash when the rednet port is not open AND hyphon is pressed (it gives the no port open error message), also it doesn't say "Logged in - Hyphon to exit" until hyphen is pressed. Not really sure what's going on here… It's weird…
Edit3: Ignore edits one and two, I updated the code to fix the way I was using parallel api, it's still broken though.
edit: updated code - still freezing
Here is the code:
local event,id,msg = os.pullEvent()
local history = {}
local function recieve()
while true do
if event == "rednet_message" then
table.insert(history, "User "..id.." > "..msg)
elseif event == "key" and id == 41 then
term.setCursorPos(1,1)
term.clear()
break
end
sleep(0)
end
end
local function broadcast()
while true do
term.setCursorPos(1,19)
rednet.broadcast(io.read)
if event == "key" and id == 41 then
break
end
sleep(0)
end
end
local function printHistory()
while true do
for i=#history-17,#history do
term.setCursorPos(1,i)
print(history[i])
end
if event == "key" and id == 41 then
break
end
sleep(0)
end
end
term.clear()
table.insert(history, "Logged in - Hyphen to exit")
parallel.waitForAny(recieve,broadcast,printHistory)
If you could help me that would be awesome! Thanks.
Edit: Typo in the code… didn't stop the freezing though. Neither did opening the side (though it should at least tell me that was wrong..?). If you press hyphen weird stuff happens, code sometimes clears and stuff like that. Though the program never stops when hyphen is pressed.
Edit2: The program does crash when the rednet port is not open AND hyphon is pressed (it gives the no port open error message), also it doesn't say "Logged in - Hyphon to exit" until hyphen is pressed. Not really sure what's going on here… It's weird…
Edit3: Ignore edits one and two, I updated the code to fix the way I was using parallel api, it's still broken though.