Jump to content




I need help with a computercraft msging system.


  • You cannot reply to this topic
2 replies to this topic

#1 12_Xx_shadow_xX

  • New Members
  • 2 posts

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 by 12_Xx_shadow_xX, 15 December 2015 - 09:44 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.

#3 12_Xx_shadow_xX

  • New Members
  • 2 posts

Posted 15 December 2015 - 09:43 AM

Thanks i really appreciate it. :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users