Please edit your post and format the code correctly with backticks.
The bit where you’re defining these global variables is commented out. A carriage return after “flags “ should sort that out.
You appear to have similar issues with other lines too:
But it’s very difficult to tell because your code isn’t correctly formatted.
Pete.