Blocks I don't know

Questions about GP commands and how to do things

Moderator: MSandro

Post Reply
mguzdial
Posts: 70
Joined: Sep 15th, '15, 11:21

Blocks I don't know

Post by mguzdial » Sep 29th, '15, 12:02

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

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: Blocks I don't know

Post by JohnM » Sep 29th, '15, 14:21

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

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: Blocks I don't know

Post by JohnM » Dec 14th, '15, 11:51

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".

Post Reply