Advertisement
Guest User

counter

a guest
Apr 8th, 2012
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1.  
  2. function screen()
  3. term.clear()
  4. term.setCursorPos(1,1)
  5. print(" compteur ")
  6. print(" dirt : "..dirt)
  7. print(" cobble : "..cobble)
  8. print(" coal : "..coal)
  9. end
  10.  
  11. function counting()
  12. rsInput = rs.getBundledInput("top")
  13.  
  14. if colors.test(rsInput, colors.brown) == true then
  15. dirt = dirt + 1
  16. end
  17. if colors.test(rsInput, colors.gray) == true then
  18. cobble = cobble + 1
  19. end
  20. if colors.test(rsInput, colors.black) == true then
  21. coal = coal + 1
  22. end
  23. count = fs.open("counter.txt", "w")
  24. count.writeLine(dirt)
  25. count.writeLine(cobble)
  26. count.writeLine(coal)
  27. count.close()
  28. screen()
  29. loop()
  30. end
  31.  
  32. function loop()
  33. while true do
  34. event = os.pullEvent()
  35.   if event == "redstone" then
  36.   counting()
  37.   end
  38. end
  39. end
  40.  
  41.  
  42. if fs.exists("counter.txt") == false then
  43. count = fs.open("counter.txt", "w")
  44. dirt = 0
  45. cobble = 0
  46. coal = 0
  47. count.writeLine(dirt)
  48. count.writeLine(cobble)
  49. count.writeLine(coal)
  50. count.close()
  51. end
  52. count = fs.open("counter.txt", "r")
  53. dirt = tonumber(count.readLine())
  54. cobble = tonumber(count.readLine())
  55. coal = tonumber(count.readLine())
  56. count.close()
  57. screen()
  58. loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement