Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("back")
- local masterd = 1
- local newstair
- function receive()
- event, id, message = os.pullEvent("rednet_message")
- print(id.." send "..message)
- read()
- if id == masterd then
- print("if1")
- if message == "error" then
- print("if2")
- maintenance()
- rednet.send(masterd,"fini")
- else
- newstair = tonumber(message)
- print("newstair : "..newstair)
- end
- else
- move(tonumber(message))
- rednet.send(masterd,"fini")
- end
- end
- function maintenance()
- print("maintenance")
- pulse(23,colors.red)
- end
- function move(go)
- local n = math.abs(go - newstair)
- if newstair <= go then
- --monter colors.red
- local blocks = blocks(n,go,1)
- pulse(blocks,colors.red)
- elseif newstair >= go then
- --descendre colors.yellow
- local blocks = blocks(n,go,0)
- pulse(blocks,colors.yellow)
- end
- end
- function blocks(n,go,i)
- if n == 2 then
- b = 22
- elseif n == 1 then
- if go == -1 then
- if i == 0 then b = 13 end
- if i == 1 then b = 9 end
- else
- if i == 0 then b = 9 end
- if i == 1 then b = 13 end
- end
- end
- print(b)
- return b
- end
- function pulse(nb, color)
- for i = 1, nb do
- redstone.setBundledOutput("right", color)
- sleep(0.4)
- redstone.setBundledOutput("right", 0)
- sleep(0.8)
- end
- end
- while true do
- receive()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement