Reset the global variables every 6 cycles.

HELLO!everyone
Recently, I encountered a problem. I don't know how to reset the global variable after the workpiece has entered the cache station B(with a capacity of 1) six times.

This is the code currently being written.

This is the source file.

Thank you for your help!