# Right mouse down?

This is what I got, but it broadcast doesn't work.

The when block keeps calling the JavaScript function, which defines outputRightclick and adds an event listener (every time it's called), but that JavaScript function is not returning anything. When you right-click, all listeners evoke outputRightclick, which logs in the console and returns true, but to what? Nothing is really being returned to the when block. Did I get anything wrong?

Good grief. It would never have occurred to me to put a JS Function in a generic when block. This is why the bad-guy security teams should all be staffed with youths.

Why not? That's how all the builtin hat blocks work in scratch. You can use an on project start hat block (see /t/onprojectopen-event/2185) and run with an argument process

function outputRightclick() {
console.log("rightclick");
}


Well, of course all the other hat blocks have js behind them! I just think of JS Function as being for the body of a procedure, not for an event.

That's not what I mean. I mean that in scratch, all hat blocks are like a predicate in a generic when, so if you can use js in a predicate then you can in a hat.

I've seen it happen before

I know, it's perfectly sensible in retrospect (apart from making the hat block look weird) and I wouldn't have boggled at a JS Function in a FOREVER IF. I just would never have thought of it.

The reason I'd like right mouse down is to make a game where you can examine things or attack things, sort of like Minecraft.

Oh, yes, it'd clearly be useful; it just conflicts with the way we use right-click in the user interface. Maybe we should consider something with middle-click.

Left click or what?

PS. I believe this is related to this topic so I am posting it here.

Left click already does something user-visible; it triggers WHEN I AM CLICKED scripts. The question is whether there's a way to make right-click user-visible in the same way. But right click is already taken, for the sprite's context menu. So I suggested trying to use middle click as the second user-visible event.

(Those of us with serious mice have at least five buttons...)

1 Like