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.
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.
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?
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.
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!)