Advertisement
Guest User

chat2

a guest
Jan 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.84 KB | None | 0 0
  1. function receive()
  2.   print( "Receiving on channel: "..channel )
  3.   modem.open( channel )
  4.   local e, s, c, r, message, dist = os.pullEvent("modem_message")
  5.   print(">"..message)
  6.   print("  ("..dist.." m away)")
  7. end
  8.  
  9. function getInput()
  10.   --global channel
  11.   print( "Ready to transmit on channel: "..channel)
  12.   nextline=""
  13.   while nextline ~= "/quit" do
  14.     io.write("\n:")
  15.     nextline = io.read()
  16.     -- todo - break long messages
  17.     modem.transmit(channel,channel, nextline)
  18.   end
  19.   print("Exiting.")
  20. end
  21.  
  22. print("What channel are you connecting to?")
  23. txtchannel = io.read()
  24. channel = tonumber(txtchannel)
  25. -- todo - input validation
  26.  
  27. print("Where is the modem?")
  28. print(" (right, left, top, bottom, front, back)")
  29. side = io.read()
  30. -- todo - input validation
  31. modem = peripheral.wrap(side)
  32.  
  33. parallel.waitForAny(receive,getInput)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement