Jump to content




Having 2 things running at the same time in one program?


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

#1 cheekycharlie101

  • Members
  • 231 posts

Posted 04 December 2012 - 09:44 AM

ok, so i wanna make a rednet irc. i know people already have but i want to have a go my self. thing is i cant figure out how to have it open to type text in and been open to be receiving rednet messages at the same time.i have thought about doing this in many different ways but none have been successful. i figure i have to move on from:
senderId, message, distance = rednet.receive()
and start using
event, id, message = os.pullEvent("rednet_message")
any ideas? thanks guys in advance

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 04 December 2012 - 09:48 AM

IRC-type chat is basically done by modifying read() to handle rednet messages, so you may wish to start by reading through it and performing basic handling of the rednet_message event in a copy of it.

#3 cheekycharlie101

  • Members
  • 231 posts

Posted 04 December 2012 - 09:54 AM

View PostLyqyd, on 04 December 2012 - 09:48 AM, said:

IRC-type chat is basically done by modifying read() to handle rednet messages, so you may wish to start by reading through it and performing basic handling of the rednet_message event in a copy of it.
how do you mean? like taking a rednet message into a varible to print it?

#4 GopherAtl

  • Members
  • 888 posts

Posted 04 December 2012 - 10:34 AM

He means you'll basically have to implement your own version of the read function which will take in a char at a time, draw them at the end of the input area, keep track of the cursor position, etc. The read function is, at heart, pullEvent loop, so you would extend it to add handlers of your own for rednet_messages and any other events your program handles, and print any messages sent by other computers to the screen above the input line where you're reading.

The only other option is to use coroutines, but that wouldn't really be any easier, as to call read() in one coroutine and not disturb it printing from another coroutine, you'd need to buffer everything on screen and handle drawing and scrolling the chat log part in your own code. I'd say it'd be a bit harder, actually, to get it really working right.

#5 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 04 December 2012 - 10:36 AM

look for the function read() in bios.lua, copy it and add a line to check for rednet messages

Edit: Ninj'd

#6 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 04 December 2012 - 08:52 PM

I prefer the coroutine method to be honest with you, do you know how to use coroutines?

#7 cheekycharlie101

  • Members
  • 231 posts

Posted 05 December 2012 - 06:36 AM

No, i have never heard of them:P there is still a lot of things i dont know about in lua. which is why i keep making posts so i can learn more. could you explain them to me?

#8 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 05 December 2012 - 10:09 AM

Well they are very complicated and I fear I am not good enough at explaining them, especially as my brain is not listening at the moment, it wants to sleep. take a look at this tutorial and then ask about anything you do not understand, hopefully by then I will have recuperated





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users