Drawbot Proofing Python Issue

Hello People,
I am currently working on a Drawbot Proof to get into Python and I wanted to have an inverter, just vor the fun of it (draw black rect and make text white).
The test works, but in the final proof, the text doesn’t accept the white fill, probably because its inside a function. But how do I get the fill from the invert function to respond to my text? Its hard to describe, i guess you have to look at it. When i put col2 into the text variables, i get a not defined error.

1 is on, 0 (or else) is off

Test:

invert=1
size=('A4Landscape')
newPage(size)
if invert==1:
    col1=(0)
    col2=(1)
else:
    col1=(1)
    col2=(0)
fill(col1)
rect(0,0,width(),height())
fill(col2)
fontSize(200)
textBox("test", (0,0, width(), height()))

In the Proof:

# Inverter
charVert=1
textVert=1

def invert(invert):
    if invert==1:
        #Farben
        col1=(0)
        col2=(1)
    else:
        #Switch
        col1=(1)
        col2=(0)

    fill(col1)
    rect(0, 0, width(), height())
    fill(col2)

My Charakter Set Proof (for example) looks like this:

# Technik
invert(charVert)
info('Charakter Set Proof')
punkt(charFontSize, raster)

# Charset
charsetString = FormattedString(charset,
    font=fontPath,
    fallbackFont=fallback,
    fontSize=charFontSize,
    lineHeight=charLh,
    align="center")
textBox(charsetString, (raster2, raster, width()-raster2*2, height()-raster2*2))

Thanks in advance

I don’t quite remember if FormattedText needs its own fill setting, but that seems to be the case. You could get a colour out of the invert() function if you return col2 instead of setting fill colour there. Then, you can say textColour=invert(charVert) which sets colour, draws a rect, then returns a colour value. Below is a sample code. It will not work as is, but I think you’ll get the point.

def invert():
    col1=(1)
    col2=(0)
    fill(col1)
    rect(0, 0, width(), height())
    return col2

textCol = invert()
fs = FormattedString("ABC", font="Helvetica", fill=(textCol))
textBox(fs, (margin, margin, width()-margin*2, height()-margin*2))

ah yes great it works
now i know how to use return

well, here is another problem:
I have site specific info functions. How can i give the invert retun to those? Those are on every page so they (just) need to adapt the font color from the formatted String.
I figured those functions should require an invert argument, but i cant figure it out.
this is my size info for example:

# Info für Schriftgrößen
def punkt(größe, xpos):
    with savedState():
        fs=FormattedString(str(größe),
            font=infoFont,
            fontSize=infoSize,
            lineHeight=infoSize)
        textBox(fs+" pt", (xpos, height()-raster-infoSize, width()/2, infoSize))