Advertisement
rjs232323

hListener turtles

Jan 16th, 2015
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. if peripheral.getType("left")=="modem" then
  2. rednet.open("left");
  3. end
  4.  
  5. print("Connecting to ROCKO SERVO");
  6. local t=false;
  7. local previousPrints="";
  8. local hasErroredOut="";
  9. function getTurtleData()
  10. if not turtle then
  11. return;
  12. end
  13. local data="{\"inspect front\":"..""..textutils.serialize(textutils.serialize(select(2,turtle.inspect()) )or "air")..",";
  14. data=data.."\"inspect down\":"..""..textutils.serialize(textutils.serialize(select(2,turtle.inspectDown())) or "air")..",";
  15. data=data.."\"inspect up\":"..""..textutils.serialize(textutils.serialize(select(2,turtle.inspectUp())) or "air")..",";
  16. data=data.."\"getSelectedSlot\":"..""..textutils.serialize(turtle.getSelectedSlot() or "")..",";
  17. data=data.."\"getItemCount\":"..""..textutils.serialize(turtle.getItemCount() or "")..",";
  18. data=data.."\"getItemDetail\":"..""..textutils.serialize(textutils.serialize(turtle.getItemDetail()) or "")..",";
  19. data=data.."\"getFuelLevel\":"..""..textutils.serialize(turtle.getFuelLevel() or "")..",";
  20. data=data.."\"getFuelLimit\":"..""..textutils.serialize(turtle.getFuelLimit() or "")..",";
  21. data=data.."\"lastPrintResult\":"..""..textutils.serialize(textutils.serialize(previousPrints))..",";
  22. data=data.."\"hasErroredOut\":"..""..textutils.serialize(textutils.serialize(hasErroredOut)).."}";
  23. local msg = data;
  24. return msg;
  25. end
  26. while not t do
  27.  
  28. local response=http.post(
  29. "http://andrei-rocko.rhcloud.com/turtle",
  30. "id="..textutils.urlEncode(os.getComputerLabel())
  31. .."&".. "data="..textutils.urlEncode(getTurtleData())
  32. )
  33. if response then
  34. local svalue=response.readAll();
  35. print (svalue);
  36. t=(tonumber(svalue)==1);
  37. end
  38. if not t then
  39. sleep(3);
  40. end
  41.  
  42. end
  43. print("LINKED TO ROCKO SERVO");
  44.  
  45.  
  46. function loadingSym(x, y, wa)
  47. local oldx, oldy = term.getCursorPos();
  48. term.setCursorPos(x,y);
  49. write(wa);
  50. term.setCursorPos(oldx,oldy);
  51. end
  52. term.setCursorPos(1,2);
  53. term.clear();
  54. local loadingSymbolArr={"|","\\","-","/"}
  55. local counterHTTP=0;
  56.  
  57. while true do
  58. loadingSym(1,1,loadingSymbolArr[(counterHTTP%4) +1 ]);
  59. counterHTTP= counterHTTP + 1;
  60. local response=http.post(
  61. "http://andrei-rocko.rhcloud.com/turtle",
  62. "id="..textutils.urlEncode(os.getComputerLabel()) .."&".. "whatDo="..textutils.urlEncode("1").."?data="..textutils.urlEncode(getTurtleData())
  63. )
  64. if response then
  65. local svalue=response.readAll();
  66. local f = loadstring(svalue);
  67. if f then
  68. setfenv(f, getfenv());
  69. local ok, msg = pcall(f);
  70. previousPrints=nil;
  71. hasErroredOut=not ok;
  72. if msg then
  73. previousPrints=msg;
  74. end
  75. if not ok then
  76. print(msg);
  77. end
  78. else
  79. print("buggy input from web?");
  80. end
  81. else
  82. loadingSym(1,1,"?");
  83. sleep(2);
  84. end
  85.  
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement