Discuss Scratch

HollyCVVA
Scratcher
11 posts

"Messages" with coding

Hi, I'm @HollyCVVA and I have a question about certain coding. So I'm trying to make a project that's an icon creator, with different hairstyles and stuff like that. Well, I also created buttons for my project, because I want to program it so when you click the different buttons, you can make accessories like glasses, bows, and earrings appear on the person. I looked at the coding inside someone else's icon creator with buttons to make accessories appear, and the way the coding worked for those buttons was with “messages.” The coding for the buttons started with “when this sprite clicked,” and then connected onto that was “broadcast (this message)”, to make accessories appear on the person when that button was clicked. Well, I realized that if that's the way those buttons worked with other icon maker projects, than I'd have to program my project like that, too. The thing is, I have absolutely no idea how “messages” work. All the other coding I've been able to do easily, but I'm stuck on this whole “broadcast message” thing and I need help with it. For one, how exactly do you create a message? And then how do you program it? Do you have to put the coding for the message under certain sprites so a specific accessory will appear on the person when the button for it is clicked? Thank you all so much for any help you can offer on this!!
PrincessFlowerTV
Scratcher
1000+ posts

"Messages" with coding

This would probably fit better in “Help With Scripts”, i'll report this to be moved for you.

Messages are one of the ways the sprites can “communicate” with each other.
For your project, put this in the button sprites:
when this sprite clicked
broadcast [change accessory v]
And this in the accessory sprite:
when I receive [change accessory v]
next costume
So each time the button is clicked, it sends the message to the accessory to go to the next costume.

Hopefully this helps you!
HollyCVVA
Scratcher
11 posts

"Messages" with coding

Thank you, that helps
HollyCVVA
Scratcher
11 posts

"Messages" with coding

Thank you so much… it worked!
NilsTheBest
Scratcher
1000+ posts

"Messages" with coding

Hi there, welcome to Scratch!

  1. Messages, or broadcasts, are a bit like “signals”, It is like a signal sent throughout every sprite in your project.
  2. Whenever the broadcast is activated, it will send that message to everyone.
  3. Whenever the sprites receive the message, they will execute the bit of code under the hat, “when I receive ”message“”.

For instance, let's say that you have the following script in sprite1:

when green flag clicked
wait (1) secs
broadcast [example broadcast v]



And in sprite2 you have the following:

when I receive [example broadcast v]
say [Hello world!] for (2) secs

That means that after the green flag is clicked, one second will elapse before the “signal” is sent to sprite2, which will execute the script.

Edit: oops, someone posted before me lol, but I'll leave that here anyways :P

————————————

Be careful not to confuse "Broadcast []“ and ”Broadcast [] and wait", I linked the article there so that you can read more and compare the differences between the two so you don't get confused

You can find more information about broadcast blocks here.
Furthermore, if you'd like to learn more about blocks like this, there exists articles on Events Blocks in the same category, and Hat Blocks on the Scratch Wiki that contains lots of helpful information on what you need ^^

Hope this helped!

Last edited by NilsTheBest (Feb. 12, 2020 15:56:22)

Powered by DjangoBB