Here's where you went wrong with that BallPosition global variable ...
The initial value of a global variable is calculated only once , at app start, and does not change by itself.
If you were to take your big chunk of logic, you could turn it into a value procedure with that same name BallPosition
(actually, it should be called BallPositionColorName) using an IF/THEN/ELSEIF/ELseif ladder like
I marked up.
The or tests in your blocks should be and tests, easy to change in place.
All 4 sides of a square must bound the ball for it to be in a square, so it's and and and and ...
Replace any get global BallPosition blocks with calls to the new value procedure,
to get the current color name for the ball's current (x,y).
You may want to double check if the X and Y of a Ball are its center, or its upper left corner.
Center is nicer for this test. Read the tool tips.
ABG