23 posts
Posted 02 April 2013 - 01:18 PM
I am trying to make a chat room type program, but when it reaches the point where it checks for os events it freezes. I need to figure out why this happens. The code below is just part of a much larger code, but it contains all of the chat room code.
Pastebin
2151 posts
Location
Auckland, New Zealand
Posted 02 April 2013 - 01:50 PM
while true do --Point where computer freezes
sleep(1)
numberMsg = #messageTable
event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent()
if event == "key" then
if modemSide == 28 then -- Enter Key
table.insert(messageTable, msg)
modem.transmit(channel, channel, msg)
msg = username..": "
elseif modemSide == 14 then -- Backspace
msg = string.sub(msg, 1, string.len(msg) - 1)
end
elseif event == "char" then
msg = msg..modemSide
elseif event == "modem_message" then
table.insert(messageTable, message)
end
...
This is happening because
os.pullEvent waits until an event is fired. In my opinion, the best way to do this is to restructure your program. You could use coroutines but I'm not familiar with them in Lua.
23 posts
Posted 02 April 2013 - 01:56 PM
while true do --Point where computer freezes
sleep(1)
numberMsg = #messageTable
event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent()
if event == "key" then
if modemSide == 28 then -- Enter Key
table.insert(messageTable, msg)
modem.transmit(channel, channel, msg)
msg = username..": "
elseif modemSide == 14 then -- Backspace
msg = string.sub(msg, 1, string.len(msg) - 1)
end
elseif event == "char" then
msg = msg..modemSide
elseif event == "modem_message" then
table.insert(messageTable, message)
end
...
This is happening because
os.pullEvent waits until an event is fired. In my opinion, the best way to do this is to restructure your program. You could use coroutines but I'm not familiar with them in Lua.
One event is key press but even that just doesn't do anything.