SHOW:
|
|
- or go back to the newest paste.
| 1 | button = "top" | |
| 2 | - | cb01 = "white" |
| 2 | + | cb01 = colors.white |
| 3 | - | cb02 = "black" |
| 3 | + | cb02 = colors.black |
| 4 | bundled = "front" | |
| 5 | cb01i = "left" | |
| 6 | cb02i = "right" | |
| 7 | platform = "back" | |
| 8 | bellr = "bottom" | |
| 9 | - | if rs.getInput(cb01i) == false and rs.getInput(cb02i) == false then |
| 9 | + | |
| 10 | - | rs.setOutput(button, true) |
| 10 | + | -- Stages: 0 -> Free, 1 -> Train arriving, 2 -> Train arrived, 3 -> Other train arrived, 4 -> Leave |
| 11 | - | else |
| 11 | + | |
| 12 | - | rs.setOutput(button, false) |
| 12 | + | stage = 0 |
| 13 | - | end |
| 13 | + | prot = 0 |
| 14 | - | sleep(1) |
| 14 | + | protectionActivated = false |
| 15 | ||
| 16 | function prs() | |
| 17 | rs.setOutput(button, true) | |
| 18 | end | |
| 19 | ||
| 20 | function deprs() | |
| 21 | if rs.getInput(button) == true then | |
| 22 | rs.setOutput(button, false) | |
| 23 | end | |
| 24 | end | |
| 25 | ||
| 26 | function bell() | |
| 27 | if rs.getInput(bellr) ~= true then | |
| 28 | rs.setOutput(bellr, true) | |
| 29 | end | |
| 30 | end | |
| 31 | ||
| 32 | function debell() | |
| 33 | if rs.getInput(bellr) == true then | |
| 34 | rs.setOutput(bellr, false) | |
| 35 | end | |
| 36 | end | |
| 37 | ||
| 38 | function activateProtection(prt) | |
| 39 | rs.setBundledOutput(bundled, prt) | |
| 40 | end | |
| 41 | ||
| 42 | ||
| 43 | function deactivateProtection(prt) | |
| 44 | rs.setBundledOutput(bundled, prt) | |
| 45 | end | |
| 46 | ||
| 47 | rs.setOutput(button, false) | |
| 48 | rs.setBundledOutput(bundled, 0) | |
| 49 | ||
| 50 | while true do | |
| 51 | if stage == 0 then | |
| 52 | prs() | |
| 53 | rs.setBundledOutput(bundled, 0) | |
| 54 | if rs.getInput(cb01i) == true or rs.getInput(cb02i) == true then | |
| 55 | stage = 1 | |
| 56 | end | |
| 57 | elseif stage == 1 then | |
| 58 | if rs.getInput(platform) == true then | |
| 59 | stage = 2 | |
| 60 | end | |
| 61 | ||
| 62 | prs() | |
| 63 | bell() | |
| 64 | if protectionActivated == false then | |
| 65 | if rs.getInput(cb01i) == true and rs.getInput(cb02i) == false then | |
| 66 | prot = cb02 | |
| 67 | activateProtection(cb02+cb01) | |
| 68 | elseif rs.getInput(cb01i) == false and rs.getInput(cb02i) == true then | |
| 69 | prot = cb01 | |
| 70 | activateProtection(cb01+cb02) | |
| 71 | else | |
| 72 | print("CAN'T FIND SEGMENT WHERE [TRUE, TRUE]!")
| |
| 73 | end | |
| 74 | protectionActivated = true | |
| 75 | end | |
| 76 | elseif stage == 2 then | |
| 77 | deprs() | |
| 78 | debell() | |
| 79 | ||
| 80 | sleep(0.25) | |
| 81 | ||
| 82 | while true do | |
| 83 | if rs.getInput(button) == true then | |
| 84 | break | |
| 85 | end | |
| 86 | sleep(0.35) | |
| 87 | end | |
| 88 | ||
| 89 | rs.setBundledOutput(bundled, cb01+cb02-prot) | |
| 90 | ||
| 91 | stage = 3 | |
| 92 | elseif stage == 3 then | |
| 93 | bell() | |
| 94 | prs() | |
| 95 | ||
| 96 | while true do | |
| 97 | if rs.getInput(cb01i) == false and rs.getInput(cb02i) == false then | |
| 98 | break | |
| 99 | end | |
| 100 | sleep(0.5) | |
| 101 | end | |
| 102 | ||
| 103 | stage = 4 | |
| 104 | elseif stage == 4 then | |
| 105 | while true do | |
| 106 | if rs.getInput(platform) == false then | |
| 107 | break | |
| 108 | end | |
| 109 | sleep(0.5) | |
| 110 | end | |
| 111 | ||
| 112 | rs.setBundledOutput(bundled, 0) | |
| 113 | stage = 5 | |
| 114 | elseif stage == 5 then | |
| 115 | if rs.getInput(cb01i) == false and rs.getInput(cb02i) == false then | |
| 116 | stage = 0 | |
| 117 | end | |
| 118 | end | |
| 119 | sleep(0.25) | |
| 120 | end |