Detecting that a side loading belt has stopped moving

Place to get help with not working mods / modding interface.
Post Reply
sparr
Smart Inserter
Smart Inserter
Posts: 1362
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Detecting that a side loading belt has stopped moving

Post by sparr »

09-17-2024, 09-16-32.png
09-17-2024, 09-16-32.png (73.97 KiB) Viewed 155 times
I would like to know when lanes A or B have stopped moving because items in lane C are blocking them. After more than a few failed attempts, I'm preparing to accept that I'll be 6-10 items late in detecting it based on the following rules:

B is stalled if B, C, and E are full (4 items)
A is stalled if A and C are full (4 items) and B+E adds up to at least 4 items

Can anyone suggest a better mechanism to detect this more reliably and/or sooner?

PS: I already have logic to deal with A, B, E being part of curved belts with a capacity different from 4 items, so don't worry about that aspect.

PPS: I know that can_insert_at() could give me more granular info than just checking for a full transport line, letting me detect an item sitting at the end of a belt before the belt fills up, but it is not performant enough for my needs.

Tertius
Filter Inserter
Filter Inserter
Posts: 836
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Detecting that a side loading belt has stopped moving

Post by Tertius »

[Edit: ugh, sorry, I overlooked you're looking for modding, not for constructing. Sorry. But may be you get an idea to indirectly find the information you seek. As far as I remember, the devs said it's not possible to build the detection you seek into the game itself, because the belt system simply doesn't provide the information if a specific belt piece is moving or not. It's built this way for performance reasons. May be you keep it like that and let the player build some detection himself with the help of circuit networks.]


As far as I thought about "is a belt moving or not?" some time ago, I came to this solution. It's independent of sideloading, because as far as I see, sideloading has nothing to do with some belt moving or not.
- take 2 consecutive pieces of belt
- wire the downstream piece (1) and set it to 'read belt content', hold mode
- wire the upstream piece (2) and set it to 'read belt content', pulse mode

the belt is moving, if:
- the last pulse from belt 2 is less than <short timout, probably 10-30> ticks ago
the belt is stalled, if:
- belt 1 has 8 items AND the last pulse from belt 2 is more than <short timeout, probably 10-30> ticks ago
the belt is empty, if:
- belt 1 has 0 items and the last pulse from belt 2 is more than <long timeout, probably 60-300> ticks ago

You need a counter to count the ticks since the last pulse (1 combinator) and one or two more to create the various combined conditions. Probably one to decide on the 8 or not 8 items, and one to combine the counter with the previous decider, so it's 3 in the end.

sparr
Smart Inserter
Smart Inserter
Posts: 1362
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Detecting that a side loading belt has stopped moving

Post by sparr »

Sadly, this is for a difficult mod, not something the player would want to build themselves.

If I could use the circuit network, I'd just check if the belt has an item on it and has pulsed in the last 32, 16, or 10 ticks. This is so easy to build in-game and soooo difficult to do with a mod :/

Post Reply

Return to “Modding help”