Fussel01

counter-x-v2_3

Oct 9th, 2012
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.68 KB | None | 0 0
  1. ---------------------------------
  2. -- Variablen
  3. ----------------------------------
  4. local s      = 0
  5. local inp    = false
  6. local z      = 0
  7. local stack  = 0
  8. local stueck = 0
  9. local count  = 0
  10. ----------------------------------
  11. -- Variablen end
  12. ----------------------------------
  13. --
  14. ----------------------------------
  15. -- file read
  16. ----------------------------------
  17. if fs.exists('count') then
  18.   local oFile=io.open('count','r')
  19.   count=tonumber(oFile:read())
  20.   oFile:close()
  21. else
  22.   local count=0
  23. end
  24. ----------------------------------
  25. -- File read end
  26. ----------------------------------
  27. --
  28. ----------------------------------
  29. -- Variablen Input
  30. ----------------------------------
  31. local tSides={input='left';reset='right';output='back'}
  32. local bInput=rs.getInput(tSides['input'])
  33. ----------------------------------
  34. -- Variablen Input end
  35. ----------------------------------
  36. --
  37. ----------------------------------
  38. -- Counter Section / File write
  39. ----------------------------------
  40. while true do
  41.   os.pullEvent('redstone')
  42.   if rs.getInput(tSides['input']) and rs.getInput(tSides['input'])~=bInput then
  43.    bInput=rs.getInput(tSides['input'])
  44.    count=count+1
  45.    local oFile=io.open('count','w')
  46.    oFile:write(count)
  47.    oFile:close()
  48.   elseif rs.getInput(tSides['reset']) then
  49.    fs.delete('count')
  50.    count=0
  51.    local oFile=io.open('count','w')
  52.    oFile:write(count)
  53.    oFile:close()
  54.   elseif rs.getInput(tSides['output']) then
  55.     count=count-1
  56.     local oFile=io.open('count','w')
  57.     oFile:write(count)
  58.     oFile:close()
  59.   end
  60. ---------------------------------------
  61. -- Counter Section / File Write end
  62. ---------------------------------------
  63. --
  64. ---------------------------------------
  65. --  Stack / Stueck Calc
  66. ---------------------------------------
  67. function _str(z)
  68.          sta = math.floor(z / 64)
  69.          stu = math.fmod(z, 64)
  70.    return sta, stu
  71. end
  72. -----------------------------------------
  73. -- Stack / Stueck Calc end
  74. -----------------------------------------
  75. function _ascii()
  76.           out = string.char(98,121,32,82,101,100,108,101,100,55,50)
  77.     return out
  78.  end
  79. -----------------------------------------
  80. -- Monitor Loop
  81. -----------------------------------------
  82. while s == 0 do
  83.          z = count
  84.          stack, stueck = _str(z)
  85.    term.redirect(peripheral.wrap('top'))
  86.          shell.run("clear")
  87.    print("        Item = XXX")
  88.    print("       Stueckzahl: "..z.." ")
  89.          print("       Anzahl in Stack")
  90.    print("      " ..stack.." Stack & " ..stueck.. " Stück")
  91.        sleep(0.1)
  92. end
  93. -----------------------------------------
  94. --  Monitor Loop end
  95. -----------------------------------------
  96. end
  97. print(newline)
  98. print("\"CC-ItemCounter\" " .._ascii().. "")
Advertisement
Add Comment
Please, Sign In to add comment