Umm, well, AppGameKit is missing some nice things from other languages, like boolean type (you have to use integer) but the AppGameKit integer is magic, and doubles as a boolean...
So try this code:
bit as integer = 0
bit = flipBit(bit)
do
Print("flipped: " + str(bit))
Sync()
loop
function flipBit(in)
out = not in
endFunction out
Mind you, only an initial value of 0 will result in a 1, any other value will result in a 0.
In your code, you'd do something like this:
if GetRawKeyPressed(KEY_B)
Brakes_On = not Brakes_On
PlaySound(brake-noise)
endif