kreezxil

Turtlescript Suck Command

Jul 23rd, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. -- this program really sucks!
  2.  
  3. -- it sucks in front, below and ontop of the turtle.
  4. -- Created Mar 21, 2014 by Kreezxil
  5.  
  6. function help()
  7. print("\
  8. usage: suck [direction] [times]\
  9. Where [direction] is one of:\
  10. front, up, down or f, u, d or\
  11. nothing at all and it will default\
  12. to 'front' and where [times] is how\
  13. many times you want it to suck, default is 1")
  14. end
  15.  
  16. function suck(dir,amt)
  17. for n=1,amt do
  18. if dir == 'f' then
  19. turtle.suck()
  20. print("I'm sucking.")
  21. elseif dir == 'd' then
  22. turtle.suckDown()
  23. print("I'm sucking from below me.")
  24. else
  25. -- only option left now is 'up'
  26. turtle.suckUp()
  27. print("I'm sucking from above me.")
  28. end
  29. end
  30. end
  31.  
  32. -- Process Arguments
  33. local tArgs = { ... }
  34. local direction = 'f'
  35. local times = 1
  36.  
  37. if #tArgs == 2 then
  38. times = tonumber( tArgs[2] )
  39. end
  40.  
  41. if #tArgs >= 1 then
  42. if tonumber( tArgs[1] ) ~= nil then
  43. -- ie suck 20, implies suck front 20
  44. times = tonumber( tArgs[1] )
  45. else
  46. direction = string.lower(string.sub( tArgs[1],1,1 ))
  47. end
  48. end
  49.  
  50.  
  51. --[[ Process command directives --]]
  52. local paramError = 0
  53.  
  54. if tArgs[1] == "help" then
  55. help()
  56. return
  57. end
  58.  
  59. if times <= 0 then
  60. print("You must specify a positive number for [times] or no number at all")
  61. paramError = paramError + 1
  62. end
  63.  
  64. if string.find("fud",direction) == nil then
  65. print("Direction must be one of: front, up, down, f, u, or d")
  66. paramError = paramError + 1
  67. end
  68.  
  69. if paramError > 0 then
  70. print("")
  71. print("Number of parameter errors are " .. paramError)
  72. print("Try:\n\tsuck help")
  73. return
  74. end
  75.  
  76. suck(direction,times)
Add Comment
Please, Sign In to add comment