tommyroyall

Client

Jul 25th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. -- So, main diagnostic: The client isnt reading. I tried to implement parallel today, not working out, must sleep. Attempt to have the input and rednet receiving all at the same time, for that is just what the solution to this problem is.
  2.  
  3. function inputLoop()
  4. while true do
  5. if inType=="key" then
  6.  ev,p1,p2,p3=os.pullEvent("char") -- Pull any events.
  7. if ev=="char" then
  8.   if ev=="char" and p1=="e" then rednet.send(hostid,"disconnect") print("Exiting") error() end -- Exit key.
  9.    print("Input: "..p1)
  10.  data=tostring(p1) -- Tostringing the parameter 1.
  11.   rednet.send(hostid,data)
  12.  data=nil
  13. end
  14. end
  15.  
  16.  
  17. if inType=="string" then
  18. data=read()
  19.  rednet.send(hostid,data) end
  20.  
  21.  end
  22. end
  23.  
  24. function mainLoop()
  25.  print("Main loop activated")
  26. rednet.send(hostid,"connect")
  27.  id,msg,dist=rednet.receive()
  28.  if id==hostid then inType=msg print("Input Type: "..inType) end -- Sends the connection notice to the server.
  29.  
  30. while true do -- Begin the loop.
  31.  
  32. ev,p1,p2,p3=os.pullEvent("rednet_message")
  33.  
  34. if ev=="rednet_message" and p1==hostid then print("["..p1.."]{"..p3.."}: "..p2) end -- Receiving.
  35. if ev=="rednet_message" and p1==hostid then if p2=="key" then inType="key" end end
  36. if ev=="rednet_message" and p1==hostid then if p2=="string" then inType="string" end end
  37. if ev=="rednet_message" and p1==hostid then if p2=="exit" then break; end end
  38.  
  39. end
  40. end
  41.  
  42. function paraCore()
  43. parallel.waitForAny(mainLoop,inputLoop)
  44. end
  45.  
  46. function intro()
  47. rednet.open("top") -- Open the top port.
  48. rednet.open("right")
  49. rednet.open("left")
  50. rednet.open("back")
  51. inType="string"
  52. print("Host ID?")
  53. hostid=tonumber(read()) -- Fetch the host ID.
  54. paraCore()
  55. end
  56.  
  57. term.clear()
  58. term.setCursorPos(1,1)
  59.  intro()
Advertisement
Add Comment
Please, Sign In to add comment