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

I need help with a computercraft msging system.

Started by 12_Xx_shadow_xX, 15 December 2015 - 02:54 AM
12_Xx_shadow_xX #1
Posted 15 December 2015 - 03:54 AM
ok so… ive been making a computercraft msging system. Everythings running as expected but theres one thing that i cant seems to fix.

So heres a small example:

1. function msgSend()
2. msg = io.read()
3. rednet.send(id,msg)
4. end
5.
6. function msgReceive()
7. id, msg = rednet.receive()
8. print(">:", msg)
9. end
10.
11. function sendAndReceiveMsges()
12. parrallel.waitForAny(msgSend, msgReceive)
13. end
14.
15. while true do
16. sendAndReceiveMsges()
17. end

the problem i have is when computer[1] is typing and computer[2] and sends a msg *BEFORE* computer[1] finishes typing its msg,
computer[1] will receive the msg and stop the typing, so pretty much the (rednet.receive()"–line 7") stops the (msg = io.read()"–line 2")
anyone know any fixes?
Edited on 15 December 2015 - 08:44 AM
Bomb Bloke #2
Posted 15 December 2015 - 09:03 AM
Make msgSend() and msgReceive() loop themselves; that way they won't return and you won't have to keep restarting them.

function msgSend()
	while true do
		msg = io.read()
		rednet.send(id,msg)
	end
end

function msgReceive()
	while true do
		id, msg = rednet.receive()
		print(">:", msg)
	end
end

parallel.waitForAny(msgSend, msgReceive)

You'll still need to deal with your print() call and your io.read() call arguing over the position of the text cursor. You might find this thread worth a look.
12_Xx_shadow_xX #3
Posted 15 December 2015 - 09:43 AM
Thanks i really appreciate it. :D/>