Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 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.
- function mainLoop()
- print("Main loop activated")
- rednet.send(tonumber(hostid),"connect")
- print("SENT")
- id,msg,dist=rednet.receive()
- if id==hostid then inType=msg print("Input Type: "..inType) end -- Sends the connection notice to the server.
- while true do -- Begin the loop.
- ev,p1,p2,p3=os.pullEvent("rednet_message")
- if ev=="rednet_message" and p1==hostid then print("["..p1.."]{"..p3.."}: "..p2) end -- Receiving.
- if ev=="rednet_message" and p1==hostid then if p2=="key" then inType="key" end end
- if ev=="rednet_message" and p1==hostid then if p2=="string" then inType="string" end end
- if ev=="rednet_message" and p1==hostid then if p2=="exit" then break; end end
- if inType=="key" then -- KEY INPUT
- ev,p1,p2,p3=os.pullEvent("char") -- Pull any events.
- if ev=="char" then
- if ev=="char" and p1=="e" then rednet.send(hostid,"disconnect") print("Exiting") error()
- end -- Exit key.
- print("Input: "..p1)
- data=tostring(p1) -- Tostringing the parameter 1.
- rednet.send(hostid,data)
- data=nil
- end
- end
- if inType=="string" then -- STRING INPUT
- data=read()
- rednet.send(hostid,data)
- end
- end
- end
- function intro()
- rednet.open("top") -- Open the top port.
- rednet.open("right")
- rednet.open("left")
- rednet.open("back")
- inType="string"
- print("Host ID?")
- hostid=read() -- Fetch the host ID.
- mainLoop()
- end
- term.clear()
- term.setCursorPos(1,1)
- intro()
Advertisement
Add Comment
Please, Sign In to add comment