Page 1 of 1

Blocks I don't know

Posted: Sep 29th, '15, 12:02
by mguzdial
There are some blocks that I don't know, perhaps because I haven't use Squeak enough. Can someone explain please?

gather: I've now even read the source code for gather, and I can't figure out what it does.

animate: I see how it's used in the new Infection project (super cool!), but I can't figure out what it does.

Thanks!
- Mark

Re: Blocks I don't know

Posted: Sep 29th, '15, 14:21
by JohnM
The animate block loops forever, pausing at the end of each iteration until the display has updated. The animate loop is intended to support animations, so it is limited to at most 60 iterations per second. The other loops, repeat, for, and while all run at full speed without synchronizing with the the display. The animate block has the same behavior as the forever block in Scratch. (Note: All loops in Scratch synchronize with the display, although you can override that using "turbo" mode.)

The gather block does a broadcast, then "gathers" the responses and returns them as a list. Any script triggered by the broadcast can return a value to gather using a return block. If a script doesn't return anything, then it doesn't add anything to the gather results. One way you might use gather is to count instances of different kinds of objects. For example, in an ecosystem simulation you might add a when I receive "is rabbit?" script to your Rabbit class that just returns true. You could then find out how many rabbits there were by calling count on the result of gather "is rabbit?".
Screen Shot 2015-09-29 at 10.22.57 AM.png

Re: Blocks I don't know

Posted: Dec 14th, '15, 11:51
by JohnM
In v043 we renamed "animate" to "forever" to more closely match Scratch. It is still the only loop block with a built-in "wait for next display cycle".