Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I've been working on a block detection system and I'm stumped. Can you help?

Asked by
Trew86 175
5 years ago

"Block detection" as in a railroad signaling system. I've been finnicking with for loops nested in for loops, nested in for loops and so on in order to navigate my tables. It always stops working in one place or another and I don't know why. I've decided to erase all that stuff and just start from square one (what I'm about to show you), which is just my tables in a module script.

here's an example of one of the tables, or "blocks".

module.Block4 = {
endPoints = {
A = {
[1] = {
Sensor = sensors.X3,
Signal = signals.S3A
}
},
B = {
[1] = {
Sensor = sensors.X4A,
Signal = signals.S4A
},
[2] = {
Sensor = sensors.X4B,
Signal = signals.S4B
}
}
}
}

The table represents a segment of railroad track. Tables A and B are the two ends of the section. However, A and B can have multiple points within if there is a switch point present. My goal is to have signals turn red when the block they're part of is occupied, yellow when the block ahead of it is occupied, and green when both the block and the block ahead are empty. So far, I've been able to detect trains using the sensors (touched event), and detect when a train moves from one block to another by assigning the train as a value for the block when it is occupied, and checking which any adjacent block was occupied by the same train, thus opening the adjacent block back up.

This is what I've been trying to do: 1. Define the adjacent blocks for each number index of each endPoint of each block (I know). 2. When a sensor is touched, set the "Train" value of the blocks it is a part of to the train that touched it. 3. Also, when a sensor is touched, for each block the sensor belongs to, check which adjacent block the train came from by checking if the adjacent block's "Train" value equals the train. If this is the case, set the adjacent block's "Train" value back to nil. 4. Lastly, for the adjacent block that the train came from, for each individual point of each endPoint, check if the block connected to that individual point is occupied or not. If it is occupied, set the opposite endPoint's individual points' signals to yellow, otherwise, set them to green.

After reading this novel, you probably think I have my work cut out for me already. That is not the case! I've been messing with this all day but I can't seem to get it right. I usually get stuck at the part where I check for the endPoint's - point's - adjacent block's - "Train" value. It always seems to be nil no matter what, not allowing me to tell how the train is traveling. Can you please just see what you can do with all this information? THANK YOU.

Answer this question