Advertisement
jamawie

Fahrstuhlsteuerung

Oct 30th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.68 KB | None | 0 0
  1. local Etage1 = {"Etage1",colors.white,     colors.orange}
  2. local Etage2 = {"Etage2",colors.magenta,   colors.lightBlue}
  3. local Etage3 = {"Etage3",colors.yellow,    colors.lime}
  4. local Etage4 = {"Etage4",colors.pink,      colors.gray}
  5. local Etage5 = {"Etage5",colors.lightGray, colors.cyan}
  6. --local Etage6 = {"Etage6",colors.purple,    colors.blue}
  7. --local Etage7 = {"Etage7",colors.brown,     colors.green}
  8. --local Etage8 = {"Etage8",colors.red,       colors.black}
  9.  
  10. local etagen = {Etage1,Etage2,Etage3,Etage4,Etage5}--,Etage6,Etage7,Etage8}
  11.  
  12. for i=1,#etagen do
  13.   etagen[i][4] = false
  14. end
  15.  
  16. local Bside = "left"
  17. local openTime = 4
  18.  
  19. function check()
  20.   if rs.getBundledInput(Bside) then
  21.     for E = 1,#etagen do
  22.       if colors.test(rs.getBundledInput(Bside), etagen[E][2]) == true then
  23.         etagen[E][4] = true
  24.       end
  25.       if colors.test(rs.getBundledInput(Bside), etagen[E][3]) == true then
  26.         etagen[E][4] = false
  27.         sleep(openTime)
  28.       end
  29.     end
  30.   end
  31. end
  32.  
  33. data = {}
  34. data[1] = 3
  35. data[2] = "up"
  36. rs.setBundledOutput(Bside,etagen[3][3])
  37. sleep(0.5)
  38. rs.setBundledOutput(Bside,0)
  39. sleep(0.1)
  40.  
  41. function move()
  42.   local stop = false
  43.   for i=1,#etagen do
  44.     if etagen[i][4] == true then
  45.       stop = true
  46.       break
  47.     end
  48.   end
  49.  
  50.   if stop == false then
  51.     data[1] = 3
  52.     data[2] = "up"
  53.     if colors.test(rs.getBundledInput(Bside), etagen[3][3]) == false then
  54.       rs.setBundledOutput(Bside, etagen[3][3])
  55.       sleep(0.5)
  56.       rs.setBundledOutput(Bside,0)
  57.     end
  58.     print("stopped")
  59.   else
  60.  
  61.     if etagen[data[1]][4] == true then
  62.       print("faehrt noch...")
  63.       return
  64.     end
  65.  
  66.     if data[2] == "down" then
  67.       for i=data[1],#etagen do
  68.         if etagen[i][4] == true then
  69.           rs.setBundledOutput(Bside, etagen[i][3])
  70.           sleep(0.5)
  71.           rs.setBundledOutput(Bside,0)
  72.           print("moving")
  73.           --etagen[i][4] = false
  74.           data[1] = i
  75.           data[2] = "up"
  76.           move()
  77.           return
  78.         end
  79.       end
  80.       data[1] = #etagen
  81.       data[2] = "down"
  82.       move()
  83.     else
  84.       for i=0,#etagen-1 do
  85.         if etagen[#etagen-i][4] == true then
  86.           rs.setBundledOutput(Bside, etagen[#etagen-i][3])
  87.           sleep(0.5)
  88.           rs.setBundledOutput(Bside,0)
  89.           print("moving")
  90.           --etagen[i][4] = false
  91.           data[1] = #etagen-i
  92.           data[2] = "down"
  93.           move()
  94.           return
  95.         end
  96.       end
  97.       data[1] = 1
  98.       data[2] = "up"
  99.       move()  
  100.     end
  101.   end
  102. end
  103.  
  104.  
  105. while true do
  106.   event,arg1,arg2,arg3 = os.pullEvent()
  107.   if event == "redstone" then
  108.     print(data[1]..", "..data[2])
  109.     check()
  110.     move()
  111.   end
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement