This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-05-08 19:09:28

jamie
Scratcher
Registered: 2007-03-28
Posts: 100+

"Broadcast" and "When I recieve" blocks?

What are the "broadcast", "broadcast ____ and wait" and "when I recieve" blocks for?


Check out my flash game site at http://subgaming.net/

Offline

 

#2 2007-05-08 22:39:41

andresmh
Scratch Team at MIT
Registered: 2007-03-05
Posts: 1000+

Re: "Broadcast" and "When I recieve" blocks?

They are typically used to pass messages from one sprite to another.

Imagine a play where a director yells  "now, it's time for jumping" and some actors start jumping. The difference is that in Scratch any sprite can yell anything at anyone else.

The tic-tac-toe sample project makes use of broadcast. Maybe you could look at the code and get an idea from there.

Also, in this project http://scratch.mit.edu/projects/andresmh/645
I use the broadcast in the sprite called 'andres' to tell the stage to start changing colors.

I hope this helps.


Andres Monroy-Hernandez | Scratch Team at the MIT Media Lab
on identi.ca and  twitter

Offline

 

#3 2007-05-09 13:39:57

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: "Broadcast" and "When I recieve" blocks?

Messages are useful for a lot more than just inter-sprite communication.  They can be used to synchronize simultaneous actions in a single sprite (a changing costume loop, a glide, and and think statement to walk across the screen while thinking, for example).

They can also be used to correct for major holes in the scratch language.
For example, to make the missing while-loop construct, replace

while <cond> do <body>

with

broadcast while-loop-1 and wait


when message while-loop-1
   forever
      if  <cond>
          <body>
      else
         Stop script

This is an ugly kluge, and I can't wait for them to put in a proper while loop, but in the meantime ...

Offline

 

#4 2007-05-20 03:31:31

mungojelly
Scratcher
Registered: 2007-05-19
Posts: 35

Re: "Broadcast" and "When I recieve" blocks?

I believe the block labelled "forever if" is a while loop-- the name confused me at first, but I'm playing with at the moment and I'm pretty sure that's what it does.

It seems to me the message passing allows Scratch to be a lot more powerful than it looks on the surface.  You can use it to implement functions, which can pass each other parameters & responses through global variables, at least..

<3

Offline

 

#5 2007-05-20 11:52:48

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: "Broadcast" and "When I recieve" blocks?

No, the forever-if loop is a forever loop with an embedded "if" or "wait".

You want to use "repeat-until" to model while loops.

The message passing is quite powerful, though it would be more powerful if you could attach parameters to the messages, direct the messages to specific sprites, and wait for messages.

Offline

 

#6 2007-06-03 12:00:48

donkeyscommand
Scratcher
Registered: 2007-06-03
Posts: 10

Re: "Broadcast" and "When I recieve" blocks?

How do you get a sprite to do something if touches another sprite?

Last edited by donkeyscommand (2007-06-03 12:01:14)

Offline

 

#7 2007-06-03 13:18:20

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: "Broadcast" and "When I recieve" blocks?

Use the "touching ___" block in the sensors section.  Set it either to the specific sprite, or to a colour on that sprite.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#8 2007-06-03 13:31:08

mohlar
Scratcher
Registered: 2007-05-24
Posts: 100+

Re: "Broadcast" and "When I recieve" blocks?

I must say, the 'Broadcast' function does seem rather more opaque than most within Scratch. A few good, simple tutorial demos wouldn't go amiss here.

Offline

 

#9 2007-06-03 17:02:04

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: "Broadcast" and "When I recieve" blocks?

The "broadcast" does not seem to be any more opaque than the other blocks to new programmers.  I think that only the programmers who have learned another programming language first find it to be a more difficult concept.

The parallel threading does allow for some sorts of bugs you would not see in serial programs (like race conditions and difficulty in synchronizing activities).

There are some changes I would like to make in the message system:

1) send <message> to <self|sprite|stage|all>
    to replace broadcast
2) send <message> with <value>
    for passing a parameter
3) wait for <message>
    could replace current "when I receive <message>" which is almost the same
   as
   forever
       wait for <message>
       do body
The new construct would be safer, as you would not start a script in the middle of   running it, and the debugging would be easier.

Last edited by kevin_karplus (2007-06-03 17:03:31)

Offline

 

Board footer