MZ Help explain how the ButtonPicture Plugin works?

Hi, everyone. I have been using the ButtonPicture plugin that comes as a default with MZ for quite a long time. However, I observed something today that I have never seen before and I would really like to know how this plugin works so I can understand what happened.

Here are the simple facts of what apparently happened:
  • Show Picture #1 on screen with ButtonPicture active for Picture #1 so it can be clicked on to call a Common Event
  • Show Picture #2 completely covers Picture #1 but not clickable (No ButtonPicture active)
  • Show Picture #3 is also on top of Picture #1 & #2 with its own ButtonPicture active for Picture #3
  • When I clicked on Picture #3, the Common Event for Picture #1 was triggered and then the Common Event for Picture #3 was triggered
Now, I had never actually tested this, but I sort of thought that having a Show Picture that has a ButtonPicture active but then covering that Picture with another image would also make the ButtonPicture unreachable. Not sure why I assumed that, but it seemed sort of logical since the image was covered up, I figured the ButtonPicture option would be there, but you couldn't click on it because it was covered. Then, when the top layer picture was removed, the underlying picture could then be clicked on.

However, it appears that multiple ButtonPictures can be active in the exact same spot and clicking on them will activate them all. In my example, the image that was farthest below was triggered first. I just tested this again and the same thing happened.

I looked at the ButtonPicture code, but I don't know enough to understand it.

Can anyone help me understand what is happening so I can understand why both ButtonPictures can be clickable at the same time when stacked?

LONG EXPLANATION: For those who wonder why in the heck would Zombie stack images like that.

Essentially, for my Sudoku Puzzle game, I have a bunch of clickable images on the screen. To implement the ability for the player to change the background, I just added a Show Picture for a black screen and then Show Pictures for the clickable options to change the background while the main game puzzle sits underneath. So there are all the clickable pictures for the main game, then that is temporarily covered by a black screen image, and then new clickable pictures are shown on top of that so the player can click to change the background. When the player is done, the change background pictures are all removed.

It never occurred to me that the clickable pictures would just happen to be on top of each other and that they both could be clicked on even though one was covering the other.

This means I will probably have to explore learning how to make a new window to do this since I would hope that a new window on top of the main game screen wouldn't experience the same problem.

I hope how I explained this makes sense.

Anyway, again, I am trying to understand why this works the way it does and I would greatly appreciate if anyone can explain it to me in simple, easy for a Zombie to understand words.

Thanks in advance!
Can anyone help me understand what is happening so I can understand why both ButtonPictures can be clickable at the same time when stacked?
Because they are.

The same thing is true for any other situation with events - if you manage to get multiple events on a tile and the player goes there and presses Enter, they'll all activate.

All the plugin does is call that same activation function without actually moving the game character onto that tile. The engine has no concept of one event "blocking" another.

You would need to include logic in your events to make them happen differently. e.g. when you display Picture 3 it turns on a switch, and the event for Picture 1 is encapsulated in a Conditional Branch that only works if that switch is off.

(to be honest, I'm not sure what the point/question of the thread is. You've already deduced the functionality, down the the order the events execute in...what additional "what is happening" do you want to know?)
Can anyone help me understand what is happening so I can understand why both ButtonPictures can be clickable at the same time when stacked?
I haven't looked at the code, but most likely: whenever the left mouse button is clicked, it looks at each currently active image, checks if the mouse position is inside the boundary of that image, and if so executes the corresponding event. So it's not in any way related to how things might look like on the screen.
@ATT_Turan Thanks! Your analogy to the multiple events was helpful. I have never seen that possibility.

My purpose for the thread was to better understand why it behaves this way. Seeing the behavior and understanding why it works that way are not the same.

And I was hoping there might be alternatives suggested. I will have to think more about the Switch option and how that would work most efficiently.

I also need to explore if learning to create a new window would be easier and better. So opening a new window on top of the main screen and then closing it when done.

I’m not clear on whether the image under the new window would still be triggered with the new window on top of it. Or if the mouse click would be limited to just that new window and not the window underneath.

@Mac15001900 Thanks, that is also helpful. When I think about it more I can see how the engine wouldn’t really know that something is on top of something else and the Use Case for that is probably pretty rare.
It's based on coordinates. If you click while the coordinates of your mouse are within the bounds of a sprite (based on the coordinates and width/height of the sprite), then it considers that sprite to be clicked. Since the sprites are in the same space, the mouse coordinates are within the bounds of both sprites, so it considers them both to be clicked.

But there's no need to make a new window. As ATT_Turan said, you just gotta use a switch to track which sprite should be considered the active one. So when the background selection UI is meant to be active, just turn on a switch (I'll call it 'backgroundUIActive' henceforth). In the common events for those background selection buttons, add a conditional statement like this one at the very beginning:
Code:
if (backgroundUIActive == OFF) {
    Exit Event Processing
}

That's psuedocode, so just convert it into event commands. And then in the common events for all your sudoku gameplay buttons, add a conditional statement like this at the very beginning:
Code:
if (backgroundUIActive == ON) {
    Exit Event Processing
}

That way, the code for each common event will be skipped whenever it's not supposed to be executed. And then just make sure to turn the switch on/off at the appropriate times.
@Arthran Thanks for that! And this helped the Switch option click (no pun intended!)

I have been thinking about this all day and I was planning on putting the switch on the Event that sets the ButtonPicture commands. And I was trying to figure out how to make that functionally work. Since the ButtonPicture will remain active once activated until the image is erased (at least I think that is how it works).

But the Switch should be in the Common Events that are called by the ButtonPicture! I can see how that makes more sense and it SOOOO much easier for me to test and implement.

Thanks again! Sometimes it just takes repetition to get concepts through this Zombie brain!

Original thread: https://forums.rpgmakerweb.com/threads/help-explain-how-the-buttonpicture-plugin-works.167195/