I wondered if it might be due to a collision (e.g. a triggered event) firing elsewhere. I'm not sure (and the docs don't say) if a triggered event only fires when the 'event processor' is at the outer level.
How about creating a local variable and putting the Tile() = 21 test in that, calculated at the top of your tile checking, replace the green and red bits with testing that instead ? See if that works, if it does, see if the value of that test is somehow changing between the initial test and the end.
It also looks to me that you are testing Tile(x,y) = something or other and as a consequence of that changing x and y. This is quite chancy for knock on effects. I'd be inclined to read Tile(x,y) into a local and then test it. What you basically have is a case/switch statement on Tile(x,y) and it is not a good idea to change the case/switch expression as you go