Flip Flop logic inside a function

Function resets itself after being called

Flip goes out of scope, aye.

What is the best option then?