i can't seem to find the message reporter block in snap, but the book im reading (learn to code anything!) says i need it. i need help and soon!
Shift+click the logo in the top-left of the editor, click
Switch to dev mode, and the [scratchblocks](message :: control)[/scratchblocks] reporter is near the bottom of the Control category.
Not at computer at moment, but if you checkout the Snap! Manual you should find updated information on the current behaviour of broadcasts.
The book you're reading sounds outdated. The message reporter has been depracted, so you shouldn't need to use it. What is the book telling you to do?
You guys should show the OP what to do instead!
Click the arrowhead at the right end of the WHEN I RECEIVE block, so instead of
it looks like this:
The first item in the DATA variable will be the message.
IF you sent data with the message. The DATA variable is just the message you sent when no data was sent.
Oh yeah you're right. I argued with Jens about that but didn't convince him, so I guess I want to forget how it actually works. :~)
For "any message" data is a list of (subject,value) if sent with the broadcast.
For a given subject there is no "subject", only data, if sent.
Yes, I know the behavior has changed over the years. The message reporter used to also report the target if there was any (it was also a hidden feature then).
edit: Oh, this is what you meant.
I actually didn't know about this behavior.
this is the one that worked. thank you so much!
What is the book telling you to do?
So I have a similar problem (seems I have an older book as well). The Message block is being used in conditions like 'while Message != "Gameover" ', but there is no Message block to insert into the statement, so the code just doesn't every catch those conditions when the message is broadcast.
To get around this we are having to expand the code to explicitly add "When Message A received" "When message B received" and add code to stop all other scripts etc to get the proper end conditions that these While message != GameOver blocks are trying to do.
Not sure if there is a better workaround to the While Message != "Gameover" syntax, open to suggestions to help my daughter learn the concepts better.
If you could let us know what book you are using and post pics of old scripts we could come up with new ones that use the latest Snap! methods
This is a simple example of how things work nowadays but they can be made more complex if needed
I can't attach media it seems (possibly too new to the forums to be allowed to upload media or something), but to summarize the issue is in checking for the message during a while loop, not just directly from a "When I receive" block
Example 1: Simple "repeat until message = a1Wins or message = a2Wins"
Example 2: Using "message == gameover" in a function block called "gameover" which is checked in a "repeat until gameover" block
The book is called "THE CODING BOOK" and the back UPC suggests it's from 2018.
The main concern is how to check messages within a repeat until block.
I moved you out of the new user category, so attaching pictures should work now.
The thing is, it sounds like the book is telling you a deprecated programming style. The right way to organize the program is to have a script per message type, because if there's one global MESSAGE reporter, and two messages come along one right after the other, one will get lost. So, to take your examples, let's say player a1 makes a winning move. Then the code that handles moves will broadcast a1Wins, and then immediately broadcast gameover. The global MESSAGE variable would then have value gameover, the message that came second.
So instead of that, you have one script that fires when a1Wins is broadcast, and another that fires when gameover is broadcast. If both are sent at almost the same time, both scripts will run, without interference. The scripts shouldn't loop (REPEAT UNTIL); they should handle just one message and finish. The same signal again will run the script again.
Attaching the photos of the code in the book.
The scripts do handle a single input message to start the script, i.e. When Message Received "start" is often the first script for each sprite or background to start processing.
The issue is in the logic within that script which loops until some end condition is met (like game over). Different missions in this book use this paradigm to continuously count something, or continuously make the enemy move, continuously make the player fall, etc. until the game has ended.
The pattern I've adopted is to have the scripts STOP all scripts when gameover is received, this works to end all other scripts which are currently looping until message == gameover (which will never happen since we don't have a message block)
I've also considered making a custom variable to store the current message and then hard code setting that variable wherever I do a broadcast message, and this works close to what the original code intended, but with a bit more hard coding for managing my own global variable.
Book Cover and UPC:
Yeah they originally wrote that in Scratch and then just changed a few details for the Snap! version. So their code runs (or used to run) in Snap! but doesn't really teach the serious computer science way of thinking about a programming problem.
Loops are okay if your program is one big script, but if you're responding to 20 different messages with 20 different scripts, you should organize your code so that each script handles the particular message instance (that is, one BROADCAST event) and then stops. Eventually someone will send the message again and then the script will get to run again. If you want to have a controlling program loop, put it in a WHEN ⚐ CLICKED.
I know rewriting their code isn't what you want to do; you want your kid to get through the book. So your ideas about how to do that will probably work. It's just really confusing if a script handles its first message (via the WHEN hat block) differently from later messages (via REPEAT UNTIL).