Fussel01

counter-x-v2.2

Oct 8th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.49 KB | None | 0 0
  1.  
  2. local s      = 0
  3. local inp    = false
  4. local z      = 0
  5. local stack  = 0
  6. local stueck = 0
  7. local count  = 0
  8.  
  9. if fs.exists('count') then
  10.   local oFile=io.open('count','r')
  11.   count=tonumber(oFile:read())
  12.   oFile:close()
  13. else
  14.   local count=0
  15. end
  16. local tSides={input='left';reset='right';output='back'}
  17. local bInput=rs.getInput(tSides['input'])
  18. while true do
  19.   os.pullEvent('redstone')
  20.   if rs.getInput(tSides['input']) and rs.getInput(tSides['input'])~=bInput then
  21.    bInput=rs.getInput(tSides['input'])
  22.    count=count+1
  23.    local oFile=io.open('count','w')
  24.    oFile:write(count)
  25.    oFile:close()
  26.   elseif rs.getInput(tSides['reset']) then
  27.    fs.delete('count')
  28.    count=0
  29.   elseif rs.getInput(tSides['output']) then
  30.     count=count-1
  31.     local oFile=io.open('count','w')
  32.     oFile:write(count)
  33.     oFile:close()
  34.   end
  35.  
  36. function _str(z)          -- Stack/Stueckrechnung
  37.          sta = math.floor(z / 64)
  38.          stu = math.fmod(z, 64)
  39.    return sta, stu
  40. end
  41.  
  42. function _ascii()
  43.           out = string.char(98,121,32,82,101,100,108,101,100,55,50)
  44.     return out
  45.  end
  46.  
  47. while s == 0 do           -- Loop Hauptschleife  
  48.          z = count
  49.          stack, stueck = _str(z)
  50.          term.redirect(peripheral.wrap('top'))
  51.          shell.run("clear")
  52.    print("        Item = XXX")
  53.    print("       Stueckzahl: " ..z.. " ")
  54.          print("       Anzahl in Stack")
  55.    print("      " ..stack.." Stack & " ..stueck.. " Stück")
  56. end
  57. end
  58. print(newline)
  59. print("\"CC-ItemCounter\" " .._ascii().. "")
Advertisement
Add Comment
Please, Sign In to add comment