Trying to create an algorithm/code in order to get my robot to follow a track which it currently can do, using a color sensor and following the inside edge. So I'm wondering how to transition to the track with broken parts the track has gaps with a max length of 20cm and only on straight parts. I also have a distance sensor available? any ideas
Currently your robot is only controlled by external factors. It always responds to external stimuli, it does not have any other operating mode.
In order to cope with missing line segments, you could add operating modes (or states) to the logic. You could detect the point where the line disappears and transition to an operating mode which goes straight on. In order to do this, it must store what does straight on mean (direction vector) and it probably should get a limit how far should it go straight on without a line present. Afterwards it could transition to a stopped sate (or operation mode).
If the line reapears in the sensors, it should switch back to line following state.