jseely

elevator

Jan 29th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. local level = 0
  2. local direction = "up"
  3.  
  4. local function writeLevel()
  5.     h = fs.open("level", "w")
  6.     h.writeLine(level)
  7.     h.close()
  8. end
  9.  
  10. local function readLevel()
  11.     h = fs.open("level", "r")
  12.     level = tostring(h.readLine())
  13.     h.close()
  14. end
  15.  
  16. local function up()
  17.     redstone.setOutput("left", true)
  18.     os.sleep(1/10)
  19.     redstone.setOutput("left", false)
  20.     level = level + 1
  21.     writeLevel()
  22.     os.sleep(1)
  23. end
  24.  
  25. local function down()
  26.     redstone.setOutput("right", true)
  27.     os.sleep(1/10)
  28.     redstone.setOutput("right", false)
  29.     level = level - 1
  30.     writeLevel()
  31.     os.sleep(1)
  32. end
  33.  
  34.  
  35.  
  36. readLevel()
  37.  
  38. while true do
  39.     if level == 180 then
  40.         direction = "down"
  41.     elseif level == 0 then
  42.         direction = "up"
  43.     end
  44.    
  45.     if direction == "up" then
  46.         up()
  47.     else
  48.         down()
  49.     end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment