Niseg

test Stray-like turtle hopper

Jun 21st, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. args ={...}
  2. local i;
  3. local f;
  4. local turns;
  5. local pulser_set={}
  6. --local dirs = { ["front"]=2,["top"]=3,["bottom"]=1}
  7. local suckfunc={["bottom"]=turtle.suckDown,["front"]=turtle.suck,["top"]=turtle.suckUp}
  8. local dropfunc={["bottom"]=turtle.dropDown,["front"]=turtle.drop,["top"]=turtle.dropUp}
  9. local aliases={["top"]="top",
  10.             ["bottom"]="bottom",
  11.             ["front"]="front",
  12.             ["up"]="top",
  13.             ["down"]="bottom",
  14.             ["forward"]="front",
  15.             ["t"]="top",
  16.             ["b"]="bottom",
  17.             ["f"]="front",
  18.             ["u"]="top",
  19.             ["d"]="bottom"
  20.             }
  21. if #args<2 or #args >3 then
  22.  
  23. if not fs.exists("hoppersetting") then print("startup <take from> <put in> [delay]");error(); end
  24.  
  25.     f=fs.open("hoppersetting","r")
  26.     pulser_set= textutils.unserialize(f.readAll())
  27.     f.close()
  28. else
  29. pulser_set[1]=#args
  30.     for i=1, pulser_set[1] do
  31.     pulser_set[i+1] = args[i]
  32.     if i<3 then
  33.         pulser_set[i+1]=aliases[args[i]]
  34.         if suckfunc[pulser_set[i+1]]== nil then
  35.             print(args[i].." is not yet supported")
  36.             error()
  37.         end
  38.     end
  39.  
  40. end
  41. end
  42. f=fs.open("hoppersetting","w")
  43. f.write(textutils.serialize(pulser_set))
  44. f.close()
  45.  
  46. local delay=1
  47. if pulser_set[4]~=nil then
  48.     delay=tonumber(pulser_set[4])
  49.     if delay==nil then  
  50.         print("bad delay");error()
  51.     end
  52. end
  53. local sf=suckfunc[pulser_set[2]]
  54. local df=dropfunc[pulser_set[3]]
  55. while true do
  56. if turtle.getItemCount(1)==0 then
  57. sf()
  58. end
  59. df()
  60. sleep(delay)
  61. end
Advertisement
Add Comment
Please, Sign In to add comment