Advertisement
Darking560

elevator

Apr 2nd, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. rednet.open("back")
  2.  
  3. local masterd = 1
  4. local newstair
  5.  
  6.  
  7. function receive()
  8.    event, id, message = os.pullEvent("rednet_message")
  9.    print(id.." send "..message)
  10.    read()
  11.    if id == masterd then
  12.       print("if1")
  13.       if message == "error" then
  14.          print("if2")
  15.          maintenance()
  16.          rednet.send(masterd,"fini")
  17.       else
  18.          newstair = tonumber(message)
  19.          print("newstair : "..newstair)
  20.       end
  21.    else
  22.       move(tonumber(message))
  23.       rednet.send(masterd,"fini")
  24.    end
  25. end
  26.  
  27. function maintenance()
  28.    print("maintenance")
  29.    pulse(23,colors.red)
  30. end
  31.  
  32. function move(go)
  33.    local n = math.abs(go - newstair)
  34.    if newstair <= go then
  35.      --monter colors.red
  36.      local blocks = blocks(n,go,1)
  37.      pulse(blocks,colors.red)
  38.    elseif newstair >= go then
  39.      --descendre colors.yellow
  40.      local blocks = blocks(n,go,0)
  41.      pulse(blocks,colors.yellow)
  42.    end
  43. end
  44.  
  45. function blocks(n,go,i)
  46.    if n == 2 then
  47.       b = 22
  48.    elseif n == 1 then
  49.       if go == -1 then
  50.       if i == 0 then b = 13 end
  51.       if i == 1 then b = 9 end
  52.       else
  53.       if i == 0 then b = 9 end
  54.       if i == 1 then b = 13 end
  55.       end
  56.    end
  57.    print(b)
  58.    return b
  59. end
  60.  
  61. function pulse(nb, color)
  62.    for i = 1, nb do
  63.    redstone.setBundledOutput("right", color)
  64.    sleep(0.4)
  65.    redstone.setBundledOutput("right", 0)
  66.    sleep(0.8)
  67.    end
  68. end
  69.  
  70.  
  71. while true do
  72.    receive()
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement