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

Chat Program, need to call for an event somehow

Started by Nakopa, 17 December 2015 - 03:26 PM
Nakopa #1
Posted 17 December 2015 - 04:26 PM
First off, my code so far: http://pastebin.com/TfNYpn99
Soooo as you can probably imagine, i want to type a message and recieve the messages of my friend at the same time.
Now the problem is, the search for the event "modem_message" blocks the whole Process and i cant type anything as long as the other one sends me a message.
Now how do i call for a event? Like os.callEvent("modem_message") with the return of True (for updated data/event recieved) and False (for no event recieved/no update since last check).
Any suggestions?
Blue #2
Posted 17 December 2015 - 04:38 PM
I don't quite know what you mean,but you might need to use to parallel API(or,if you want to go hardcore,use coroutines) to be able to type and receive messages at the same time. Alternatively,you could create a custom read() function in your while loop.

-- forums messed up indenting
while true do
local event,e1,e2 = os.pullEvent()
if event == "char" then
  -- make a custom read()
elseif event == "modem_message" then
  -- add code for receiving messages
end
end
Nakopa #3
Posted 17 December 2015 - 04:44 PM
I don't quite know what you mean,but you might need to use to parallel API(or,if you want to go hardcore,use coroutines) to be able to type and receive messages at the same time. Alternatively,you could create a custom read() function in your while loop.

-- forums messed up indenting
while true do
local event,e1,e2 = os.pullEvent()
if event == "char" then
  -- make a custom read()
elseif event == "modem_message" then
  -- add code for receiving messages
end
end
ahhhh i see. Didnt know there was a parallel api
Lupus590 #4
Posted 17 December 2015 - 06:21 PM
Here's a list of official APIs, with links to documentation.
Bomb Bloke #5
Posted 17 December 2015 - 10:01 PM
You might find my comment here useful.