tommyroyall

Untitled

Jul 25th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 mainLoop()
  4. print("Main loop activated")
  5.     rednet.send(tonumber(hostid),"connect")
  6. print("SENT")
  7.     id,msg,dist=rednet.receive()
  8.   if id==hostid then inType=msg print("Input Type: "..inType)
  9. end -- Sends the connection notice to the server.
  10.  
  11. while true do -- Begin the loop.
  12.  
  13.  ev,p1,p2,p3=os.pullEvent("rednet_message")
  14.  
  15.    if ev=="rednet_message" and p1==hostid then print("["..p1.."]{"..p3.."}: "..p2) end -- Receiving.
  16.    if ev=="rednet_message" and p1==hostid then if p2=="key" then inType="key" end end
  17.    if ev=="rednet_message" and p1==hostid then if p2=="string" then inType="string" end end
  18.    if ev=="rednet_message" and p1==hostid then if p2=="exit" then break; end end
  19.  
  20. if inType=="key" then -- KEY INPUT
  21.     ev,p1,p2,p3=os.pullEvent("char") -- Pull any events.
  22.         if ev=="char" then
  23.             if ev=="char" and p1=="e" then rednet.send(hostid,"disconnect") print("Exiting") error()
  24.              end -- Exit key.
  25.         print("Input: "..p1)
  26.          data=tostring(p1) -- Tostringing the parameter 1.
  27.         rednet.send(hostid,data)
  28.     data=nil
  29. end
  30. end
  31.  
  32.  
  33. if inType=="string" then -- STRING INPUT
  34.     data=read()
  35.   rednet.send(hostid,data)
  36. end
  37.  
  38.  end
  39.  
  40. end
  41.  
  42. function intro()
  43.   rednet.open("top") -- Open the top port.
  44.   rednet.open("right")
  45.   rednet.open("left")
  46.   rednet.open("back")
  47.   inType="string"
  48. print("Host ID?")
  49.  hostid=tonumber(read()) -- Fetch the host ID.
  50.    mainLoop()
  51. end
  52.  
  53.   term.clear()
  54.   term.setCursorPos(1,1)
  55. intro()
Advertisement
Add Comment
Please, Sign In to add comment