Fussel01

counter-v3_1

Oct 10th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 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 count  = 0
  22. local item = 'Cleanstone'
  23. local function display(count)
  24.   term.clear()
  25.   term.setCursorPos(1,1)
  26.   print("     Item = "..item.." ")
  27.   print("    Gesamt Vorrat =  "..count)
  28.   print("        entspricht")
  29.   print("      "..math.floor(count/64).." Stacks & "..count%64)
  30. end
  31. ----------------------------------
  32. -- Variablen und Functions ende
  33. ----------------------------------
  34. --
  35. ----------------------------------
  36. -- Counter Section mit File write
  37. ----------------------------------
  38. term.redirect(peripheral.wrap('top'))
  39. while true do
  40.   display(count)
  41.   os.pullEvent('redstone')
  42.   if rs.getInput(tSides['input']) and rs.getInput(tSides['input'])~=bInput then
  43.    count=count+1
  44.    local oFile=io.open('count','w')
  45.    oFile:write(count)
  46.    oFile:close()
  47.   elseif rs.getInput(tSides['reset']) then
  48.    fs.delete('count')
  49.    count=0
  50.    local oFile=io.open('count','w')
  51.    oFile:write(count)
  52.    oFile:close()
  53.   elseif rs.getInput(tSides['output']) and rs.getInput(tSides['output'])~=bInput2 then
  54.    count=count-1
  55.    local oFile=io.open('count','w')
  56.    oFile:write(count)
  57.    oFile:close()
  58.   end
  59.   bInput=rs.getInput(tSides['input'])
  60.   bInput2=rs.getInput(tSides['output'])
  61. end
  62. ---------------------------------------
  63. -- Counter Section mit File Write ende
  64. ---------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment