ecco7777

CC turtle filler Controler

May 11th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | None | 0 0
  1. file="bild"
  2. slot={}
  3. chars={}
  4. slot[" "]=12
  5. slot["0"]=1
  6. slot["1"]=2
  7. slot["2"]=3
  8. slot["3"]=4
  9. slot["4"]=5
  10. slot["5"]=6
  11. slot["6"]=7
  12. slot["7"]=8
  13. slot["8"]=9
  14. slot["9"]=10
  15. slot["a"]=11
  16. slot["b"]=12
  17. slot["c"]=13
  18. slot["d"]=14
  19. slot["e"]=15
  20. slot["f"]=16
  21.  
  22. function getCharCount(str,char)
  23. charnum=0
  24. for i=1, #str do
  25. if string.sub(str,i,i)==char then
  26. charnum=charnum+1
  27. end
  28. end
  29. return(charnum)
  30. end
  31.  
  32. function fileToTable(file)
  33. if fs.exists(file)~=true then
  34. print("file"..file.." not found")
  35. return(false)
  36. end
  37. fp=fs.open(file,"r")
  38. line={}
  39. i=1
  40. line[i]=fp.readLine()
  41. if line[i]==nil then return(false) end
  42. while line[i]~=nil do
  43. i=i+1
  44. line[i]=fp.readLine()
  45. end
  46. return(line)
  47. end
  48.  
  49. img=fileToTable(file)
  50.  
  51. i=1
  52. i2=1
  53. i3=1
  54. while img[i]~=nil do
  55. for i2=1, #img[i] do
  56. chars[i3]=string.sub(img[1],i2,i2)
  57. i3=i3+1
  58. end
  59. i=i+1
  60. end
  61.  
  62. onechar=""
  63. for i=1, #img do
  64. onechar=onechar..img[i]
  65. end
  66. term.clear()
  67. term.setCursorPos(1,1)
  68. term.write("S1 weiß: "..tostring(getCharCount(onechar,"0")))term.setCursorPos(1,2)
  69. term.write("S2 orange: "..tostring(getCharCount(onechar,"1")))term.setCursorPos(1,3)
  70. term.write("S3 magenta: "..tostring(getCharCount(onechar,"2")))term.setCursorPos(1,4)
  71. term.write("S4 hellblau: "..tostring(getCharCount(onechar,"3")))term.setCursorPos(1,5)
  72. term.write("S5 gelb: "..tostring(getCharCount(onechar,"4")))term.setCursorPos(1,6)
  73. term.write("S6 hellgrün: "..tostring(getCharCount(onechar,"5")))term.setCursorPos(1,7)
  74. term.write("S7 pink: "..tostring(getCharCount(onechar,"6")))term.setCursorPos(1,8)
  75. term.write("S8 grau: "..tostring(getCharCount(onechar,"7")))term.setCursorPos(21,1)
  76. term.write("S9 hellgrau: "..tostring(getCharCount(onechar,"8")))term.setCursorPos(21,2)
  77. term.write("S10 cyan: "..tostring(getCharCount(onechar,"9")))term.setCursorPos(21,3)
  78. term.write("S11 lila: "..tostring(getCharCount(onechar,"a")))term.setCursorPos(21,4)
  79. term.write("S12 blau: "..tostring(getCharCount(onechar," ")+getCharCount(onechar,"b")))term.setCursorPos(21,5)
  80. term.write("S13 braun: "..tostring(getCharCount(onechar,"c")))term.setCursorPos(21,6)
  81. term.write("S14 grün: "..tostring(getCharCount(onechar,"d")))term.setCursorPos(21,7)
  82. term.write("S15 rot: "..tostring(getCharCount(onechar,"e")))term.setCursorPos(21,8)
  83. term.write("S16 schwarz: "..tostring(getCharCount(onechar,"f")))term.setCursorPos(1,9)
  84.  
  85.  
  86. print("Höhe: "..tostring(#img))
  87. print("Breite: "..tostring(#img[1]))
  88. e,key=os.pullEvent("key")
  89. while key~=28 do
  90. e,key=os.pullEvent("key")
  91. end
  92.  
  93. for i=1, #chars do
  94. turtle.select(slot[string.sub(onechar,i,i)])
  95. if turtle.getItemCount(slot[string.sub(onechar,i,i)])>0 then
  96. turtle.drop(1)
  97. else
  98. term.write("Bitte Material nachfüllen und Taste drücken")
  99. e,key=os.pullEvent("key")
  100. while key~=28 do
  101. e,key=os.pullEvent("key")
  102. end
  103. term.write("                                           ")
  104. turtle.drop(1)
  105. end
  106. end
Add Comment
Please, Sign In to add comment