Getting the z-order of an object

Is there a way to read out and compare the z-order of objects?

I would like to implement a drag & drop. Unfortunately, all objects at the mouse position react to the “touching mouse-pointer?” block. I only want to filter out the upper object.

My approach is to search for all objects at the mouse position with “sprites at mouse-position” and then only address the one with the highest z-order. But how do I get the z-order as a number? There doesn't seem to be an attribute for this.

It would be great if the my-block (my neighbors etc.) also had a “my z-order” attribute. Or can this be found somewhere else?

Been asked by someone else:

Thank you, this works perfectly for me.

Nevertheless, it would be helpful to have "my z-order" or "my layer" as an attribute in the my-Block.

I made it into a custom block, if it helps:
my z-order

Just as a tip (for @tsal ) you can drag and drop snap script pics into snap, and you'll get the code in that image back into the editor.

Thanks for the tip, I didn’t know that before. It even works in multiple languages!