MZ (Solved) Q: Help with simple scripts that checks if surrounding events are present

First off, hello! It's been a while. Man, back in the days, my eventing was crazy on point, and my Ruby/JS were basic-ish, but decent. I'm kinda getting back into it, and I'm a bit rusty.

Here it is. I've got an event named Gem and events named Dirt. There will be more around the map. I want the Gem event to turn self switch A on which will allow it to be picked up, only if there are no Dirt events surrounding it within one tile, all 8 directions. So, on player touch (no need to parallel it), it runs a script that checks if there are any Dirt events within one tile. If there are none, then turn self switch A on, and on A=on event page, it can be picked up.

The problem is my scripts aren't detecting this properly and I'm not quite sure why not. I'm pretty sure I'm doing something wrong, just not sure what.

Event Trigger PlayerTouch, Priority same as player, Conditional branch, if self switch A=off (which it is by default). Event page 2, changes color of gem to give visual indicator, PlayerTouch/Priority Same, and allows itself to be picked up then erases event. The Dirt events are named Dirt. When the player removes them, the events are erased.

If I start with dirt around the Gem then I remove one and try to pick it up, I get my debug message stating dirt nearby. But once I clear all blocks within one tile of the gem, it still says dirt nearby. But if I start with no dirt blocks around it, I get my debug message for no dirt, and it turns A on. There's gotta be something wrong in the way I'm checking for Dirt events within one tile.

edit: Okay, it's not me. I'm a sane individual. It's the way RPGM handles erased events. They're still technically there. I have to check their status. Hold on, I think I can fix this. Okay, I had to edit the if hasdirt logic to view erased events as no dirt.

Original thread: https://forums.rpgmakerweb.com/threads/solved-q-help-with-simple-scripts-that-checks-if-surrounding-events-are-present.183912/