It's to do with global and local variables. Local variables exist in def main, but to write values to the output port they have to be global - so they can exist outside def main.
In a similar manner, any 'counter' type variable that increments every frame needs to exist outside of def main - it needs to be global so it persists when the code is run the next frame.
This will count
def main():
global counter
frame = doc.GetTime().GetFrame(doc.GetFps())
if frame == 0:
counter = 0
else:
counter += 1
print counter
so your code would be something like
def main():
global red, blue, yell, counter
frame = doc.GetTime().GetFrame(doc.GetFps())
if frame == 0:
red, blue, yell = False, False, False
counter = 0
else:
if frame % f1 == 0:
if counter < 3:
counter = counter + 1
red = not red
blue = False
print counter
elif counter > 3:
counter = 0
although I don't think the last part gets executed