Fussel01

Counter-rc

Oct 11th, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 KB | None | 0 0
  1. ----------------------------------
  2. -- file auslesen
  3. ----------------------------------
  4. if fs.exists('count') then
  5.   local oFile=io.open('count','r')
  6.   count=tonumber(oFile:read())
  7.   oFile:close()
  8. else
  9.   local count=0
  10. end
  11. ----------------------------------
  12. -- File auslesen ende
  13. ----------------------------------
  14. --
  15. ----------------------------------
  16. -- Variablen und Functions
  17. ----------------------------------
  18. local tSides={input='left';reset='right';output='back';monitor='top'}
  19. local bInput=rs.getInput(tSides['input'])
  20. local bInput2=rs.getInput(tSides['output'])
  21. local item = 'Cleanstone'
  22. local function display(count)
  23.   term.clear()
  24.   term.setCursorPos(1,1)
  25.   print("     Item = "..item.." ")
  26.   print("    Gesamt Vorrat =  "..count)
  27.   print("        entspricht")
  28.   print("      "..math.floor(count/64).." Stacks & "..count%64)
  29. end
  30. ----------------------------------
  31. -- Variablen und Functions ende
  32. ----------------------------------
  33. --
  34. ----------------------------------
  35. -- Counter Section mit File write
  36. ----------------------------------
  37. term.redirect(peripheral.wrap('top'))
  38. while true do
  39.   display(count)
  40.   os.pullEvent('redstone')
  41.   if rs.getInput(tSides['input']) and rs.getInput(tSides['input'])~=bInput then
  42.    count=count+1
  43.    local oFile=io.open('count','w')
  44.    oFile:write(count)
  45.    oFile:close()
  46.   elseif rs.getInput(tSides['reset']) then
  47.    fs.delete('count')
  48.    count=0
  49.    local oFile=io.open('count','w')
  50.    oFile:write(count)
  51.    oFile:close()
  52.   elseif rs.getInput(tSides['output']) and rs.getInput(tSides['output'])~=bInput2 then
  53.    count=count-1
  54.    local oFile=io.open('count','w')
  55.    oFile:write(count)
  56.    oFile:close()
  57.   end
  58.   bInput=rs.getInput(tSides['input'])
  59.   bInput2=rs.getInput(tSides['output'])
  60. end
  61. ---------------------------------------
  62. -- Counter Section mit File Write ende
  63. ---------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment