Broadcast Green Flag Issue

We would like to start the Pacman game by pressing the letter "s" on the keyboard. We used the blocks [When "s" Key Pressed] [Broadcast Green Flag] to accomplish this:


However, when we start the game using this method, there is a bug that occurs every other time that we launch the program. Each "Pill" clone has a code bock that says [When "Touching Packman"] [Delete This Clone]:


The code works every other game launch when using the [Broadcast Green Flag] block. It works 100% of the time when the game is launched by clicking the green flag in the upper righthand corner of the stage.

Here's a link to the Pacman program:

There is something subtle occurring that we have not been able to isolate. If anyone has any suggestions, any hints would be very welcome!

P.S. At first we thought this might be related to a timing issue. However, we created a version in which all of the code was placed in a single block launched by a single green flag in the stage script (to eliminate timing variation in the order which different parallel processes were initiated). This did not affect the result.

When you broadcast green flag, does the stop button tun into a square?

Yes ... every other time that it is launched with [Broadcast Green Flag], the "Stop" button turns into a square. And when that occurs, the program does not run properly.

... After a forum search, I now see that when the "Stop" button turns into a square, it indicates that "When" blocks will not run. But why does launching with the [Broadcast Green Flag] block cause this to occur ... and why does it only occur every other launch?

... found a note from @BH that states

I am not sure how to avoid this condition, so that WHEN scripts will run when the game is launched.

Note: We plan to use MicroBlocks to send an "s" keypress when an arcade control button connected to a micro:bit is pressed. When this occurs, we would like to launch the game from a Raspberry Pi inside the arcade cabinet.

I knew it. Like you said, it is in fact to stop the generic when blocks from running. I personally think it's a bug, because broadcasting green flag in the code should keep the generic when blocks running, but the user should have to click a button in the gui to stop the generic when blocks.

When the Raspberry Pi is in the arcade cabinet, the user won't have access to a keyboard or mouse to click the "Stop" button when it is a square.

Is there another way to perform this function so that the "When" blocks are enabled and run correctly when the game is launched?

I was saying that I think it's a bug, and I also explained the behavior that I personally think should be like. To solve your issue right now, try to not use the generic when block.

The [When] block in question is this:


Is there a workaround that could be used in place of this block to avoid the problem?

OK, tried this and it seemed to work:


We still have some work to do, but here's the current arcade cabinet layout and design:

The issue is to avoid a buggy or malicious generic WHEN from making it impossible for the user to stop the project. I don't think we can meet all possible design goals simultaneously.

Fortunately there's a workaround, but there is still a lot that I don't understand about the parameters involved.

  1. In this instance, the problem is encountered when the program is re-launched after the Snap! program has ended.

  2. It consistently occurs every other time the program is launched. Why does it only occur every other time that the program is launched?

Is there documentation or an explanation of this phenomenon? (Thanks)

Manual page 6 footnote: "One of the hat blocks, the generic “when anything” block , is subtly different from the others. When the stop sign is clicked, or when a project or sprite is loaded, this block doesn’t test whether the condition in its hexagonal input slot is true, so the script beneath it will not run, until some other script in the project runs (because, for example, you click the green flag). When generic when blocks are disabled, the stop sign will be square instead of octagonal." That's really all I know about it. From what you're saying, maybe we detect when a project has no active scripts even if you didn't click the stop sign? Or maybe you do stop the project with the red stop sign.

Thanks for pointing me to the explanation in the manual. Somehow I had overlooked the footnote on Page 6.

Normally the Pacman game ends with [StopAll] when the ghost catches the Pacman (using the code below). However, during testing I was interrupting the game by clicking the red stop sign to terminate the game.


The reason that I am interested is because we have invited the class to create a library of arcade games, and they're having a lot of fun doing this.

However, the same condition that I encountered is almost certain to come up again in one of the games that they are creating, and I wanted to give them the clearest possible explanation of how they can avoid this condition. (Thanks!)

De nada.