Fussel01

counter-x-v2

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