Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- button = "top"
- cb01 = colors.white
- cb02 = colors.black
- bundled = "front"
- cb01i = "left"
- cb02i = "right"
- platform = "back"
- bellr = "bottom"
- -- Stages: 0 -> Free, 1 -> Train arriving, 2 -> Train arrived, 3 -> Other train arrived, 4 -> Leave
- stage = 0
- prot = 0
- protectionActivated = false
- function prs()
- rs.setOutput(button, true)
- end
- function deprs()
- if rs.getInput(button) == true then
- rs.setOutput(button, false)
- end
- end
- function bell()
- if rs.getInput(bellr) ~= true then
- rs.setOutput(bellr, true)
- end
- end
- function debell()
- if rs.getInput(bellr) == true then
- rs.setOutput(bellr, false)
- end
- end
- function activateProtection(prt)
- rs.setBundledOutput(bundled, prt)
- end
- function deactivateProtection(prt)
- rs.setBundledOutput(bundled, prt)
- end
- rs.setOutput(button, false)
- rs.setBundledOutput(bundled, 0)
- while true do
- if stage == 0 then
- prs()
- rs.setBundledOutput(bundled, 0)
- if rs.getInput(cb01i) == true or rs.getInput(cb02i) == true then
- stage = 1
- end
- elseif stage == 1 then
- if rs.getInput(platform) == true then
- stage = 2
- end
- prs()
- bell()
- if protectionActivated == false then
- if rs.getInput(cb01i) == true and rs.getInput(cb02i) == false then
- prot = cb02
- activateProtection(cb02+cb01)
- elseif rs.getInput(cb01i) == false and rs.getInput(cb02i) == true then
- prot = cb01
- activateProtection(cb01+cb02)
- else
- print("CAN'T FIND SEGMENT WHERE [TRUE, TRUE]!")
- end
- protectionActivated = true
- end
- elseif stage == 2 then
- deprs()
- debell()
- sleep(0.25)
- while true do
- if rs.getInput(button) == true then
- break
- end
- sleep(0.35)
- end
- rs.setBundledOutput(bundled, cb01+cb02-prot)
- stage = 3
- elseif stage == 3 then
- bell()
- prs()
- while true do
- if rs.getInput(cb01i) == false and rs.getInput(cb02i) == false then
- break
- end
- sleep(0.5)
- end
- stage = 4
- elseif stage == 4 then
- while true do
- if rs.getInput(platform) == false then
- break
- end
- sleep(0.5)
- end
- rs.setBundledOutput(bundled, 0)
- stage = 5
- elseif stage == 5 then
- if rs.getInput(cb01i) == false and rs.getInput(cb02i) == false then
- stage = 0
- end
- end
- sleep(0.25)
- end
Advertisement
Add Comment
Please, Sign In to add comment