Jump to content




[Lua][Qeustion]Help with my chat program


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

#1 Spongy141

  • Members
  • 526 posts
  • Location'Merica

Posted 05 December 2012 - 04:26 AM

Hello, I already know that my chat program works, and has no errors, but I do not like were I have to wait to send a message for someone to reply first, someone on a CC server I play said you needed to do something like.
os.pullEvent
and I admit, I am not the good with some Lua in CC, like os, but here's my chat programs code. All i really want to know is were to put it, and what to put, because Im not good with os. thanks.
function top()
  term.clear()
  term.setCursorPos(1,1)
  term.setTextColor(colors.purple)
  print("Welcome to Chatv")
  term.setTextColor(colors.gray)
  print("====================================================")
end
function detectDevice(DeviceName)
DeviceSide="none"
for k,v in pairs(redstone.getSides()) do
if peripheral.getType(v)==DeviceName then
   DeviceSide = v
   break
end
end
  return(DeviceSide)
end
top()
ModemSide=detectDevice("modem")
rednet.open(ModemSide)
term.setTextColor(colors.green)
write("Username: ")
term.setTextColor(colors.white)
local user = read()
term.clear()
term.setCursorPos(1,1)
top()
while true do
  term.setTextColor(colors.lime)
  write("Message: ")
  term.setTextColor(colors.white)
  local a = read()
  rednet.broadcast(user.. ": " ..a)
  id, msg = rednet.receive()
  print(id.. ": is sending a message")
  print(msg)
end


#2 Doyle3694

  • Members
  • 815 posts

Posted 05 December 2012 - 04:30 AM

You have 2 options really, either, you could to some extent recode read(), so that it will also accept a rednet_message event and print it out. OR, you could trick around some with parallel API. both working, I personally would have taken the first, more "legit" route. Plus I have no experience with parallel. Though, that being said, I think parallel is abit easier to use, though I also think the first route is safer, since then its your program from the bottom sort of say.

#3 ChaddJackson12

  • Members
  • 264 posts

Posted 05 December 2012 - 04:38 AM

I'm not too good with this stuff, but I think I might be able to help. Instead of someone having to reply, just have a "Reload" option, where it would reload the program and load the new messages. Or you could have a while loop reloading the program every so often so that it could load the new messages.

#4 Doyle3694

  • Members
  • 815 posts

Posted 05 December 2012 - 04:50 AM

chadd, he wants to read and reveive at the same time. and no timeframe or something, instant.

#5 Spongy141

  • Members
  • 526 posts
  • Location'Merica

Posted 05 December 2012 - 12:59 PM

View PostDoyle3694, on 05 December 2012 - 04:30 AM, said:

You have 2 options really, either, you could to some extent recode read(), so that it will also accept a rednet_message event and print it out. OR, you could trick around some with parallel API. both working, I personally would have taken the first, more "legit" route. Plus I have no experience with parallel. Though, that being said, I think parallel is abit easier to use, though I also think the first route is safer, since then its your program from the bottom sort of say.
So I would just do
local a = read() id, msg = rednet.receive()
then just leave the rest as is?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users