DrFair

Pump computer

Jul 10th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. function goFor(n)
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. term.write("Going forward "..n.." blocks.")
  5. for n=1,n do
  6. rs.setOutput("left",true)
  7. os.sleep(1)
  8. rs.setOutput("left",false)
  9. os.sleep(0.5)
  10. rs.setOutput("right",true)
  11. os.sleep(0.2)
  12. rs.setOutput("right",false)
  13. os.sleep(0.2)
  14. end
  15. end
  16.  
  17. function reset()
  18. term.clear()
  19. term.setCursorPos(1,1)
  20. term.write("How many blocks to go forward?")
  21. term.setCursorPos(1,2)
  22. term.write("Blocks: ")
  23. term.setCursorPos(9,2)
  24. term.setCursorBlink(true)
  25. str = ""
  26. end
  27.  
  28. reset()
  29.  
  30. while true do
  31. event,char = os.pullEvent()
  32. if event == "char" then
  33. if char == "0" or char == "1" or char == "2" or char == "3" or char == "4" or char == "5" or char == "6" or char == "7" or char == "8" or char == "9" then
  34. if #str < 2 then
  35. str = str..char
  36. term.setCursorPos(9,2)
  37. term.write(str.." ")
  38. term.setCursorPos(9,2)
  39. term.write(str)
  40. term.setCursorBlink(true)
  41. end
  42. end
  43. elseif event == "key" then
  44. if char == 28 and #str > 0 then
  45. goFor(tonumber(str))
  46. reset()
  47. elseif char == 14 and #str > 0 then
  48. str = string.sub(str,1,#str-1)
  49. term.setCursorPos(9,2)
  50. term.write(str.." ")
  51. term.setCursorPos(9,2)
  52. term.write(str)
  53. term.setCursorBlink(true)
  54. end
  55. end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment