Nestable Sprites for Scratch

NestingBYOB 2.0 is here for you to download. I’m surprised and a bit scared about the enthusiastic reception of the my little build-your-own-block experiment for Scratch. I never intended BYOB to be actually used in highschool classrooms and university courses in different parts of the world.

It also feels wonderful! I have been getting excellent suggestions from very bright people, and the idea to gradually distill class-like constructs out of Scratch and turn BYOB into a CS intro environment has got me hooked (and slightly overwhelmed, too).

So I decided to share only those experiments I feel confident about, even if the whole of them doesn’t yet go all the way towards that starry goal. In BYOB 2.0 I resisted the urge to add new blocks, focusing instead on improving the experience to let you create your own ones, and on introducing compositional object relationships to Scratch. Still, please expect to encounter many bugs.

What’s new in BYOB 2.0:

custom blocks (functional recursion)

  • now have all Scratch 1.4 features (esp. string functions)
  • can open / import any Scratch project (also older ones)
  • arguments now take  both numerical and text input (and reporters)
  • double click on a custom reporter block to show its result
  • fixed the block editor’s answer field to improve drag & drop
  • new debugging functions (error blocks are displayed red)
  • fixed escaping out of infinite atomic loops (thanks to Brian Harvey for catching this!)
  • the block editor now is resizable (thanks to Dan Garcia for suggesting this!)

nestable sprites (structural recursion)

  • you can now create composite sprites (made out of subsprites)
  • sprites can be nested infinitely, making them “parts” of more complex simulations
  • subsprites follow their owner’s motion, heading, resizing and graphical effects, and serve as their owner’s extended sensors
  • subsprites can be set to follow their owner’s rotation, or to rotate independently

other

  • you can now share sprites (also nested ones) in a mesh network
  • built-in compiler lets you convert any Scratch/BYOB project into an .exe
  • autoscrolling
  • scrolling by dragging
  • undo (!) - Why didn’t I think of this before…

Elements - blocks of code all the way down to the VM

  • you can now inspect (and awkwardly edit) any non-custom standard Scratch block in my experimental Elements for Smalltalk GUI. This is a taste of Zukunftsmusik…

Smalltalk has helped

BYOB’s new nestable sprites feature was not nearly as difficult to implement as I first expected, because Smalltalk has helped. A central problem was to recursively propagate the owner sprite’s settings to all of its subsprites whenever they are changed. This is about navigating down an ordered tree towards its leaf nodes and basically trivial. What’s tedious about it is that you have to add additional methods for each and every possible modification of any node, which is not exactly “copy & paste” but nonetheless repetitive and boring stuff. Here Smalltalk’s meta-programming capabilities allowed me to write a single simple method instead managing that task for any context:

spread
“private - apply the method calling me to all subsprites
| sel args |
subsprites isEmpty ifTrue: [^self].
sel _ thisContext sender method selector.
args _ OrderedCollection new.
1 to: thisContext sender method numArgs do: [:idx |
    args add: (thisContext sender tempAt: idx) ].
subsprites do: [:eachPart |
    args isEmpty
        ifTrue: [ eachPart perform: sel]
        ifFalse: [ eachPart perform: sel withArguments: args asArray]]

A simple, consistent syntax is worth more than abundant libraries. Gotta love languages for the lazy!

Enjoy!

-Jens Mönig

12 Responses to “Nestable Sprites for Scratch”

  1. henley Says:

    Jens, you rock! Did you say it was used in high-schools around the world? Congratulations! I am just a kid, and I hope to live to be as successful as you.

  2. Google-TCW Says:

    Hi from google Google-TCW

  3. Adam Truncale Says:

    Hey Jens. I am a high school computer science teacher that uses Scratch (among other things) to teach computer science. My question/request is: Are you going to add the save and load block to the lists in this BOYB version? Or can you modify your version 1.2 mod to the 1.4 version of scratch? I’d really like to teach my kids file input and output using such a ’safe’ environment. Thank you for you time!

  4. Anonymous Says:

    Hi Adam,

    it’s wonderful that you’re using Scratch to teach CS in high school (I wish Scratch would have been around when I was in high school!). I agree with you that data persistence is an important concept to teach at school. I am, however, currently not planning to add any blocks to BYOB which aren’t in standard Scratch (except, of course, custom blocks), because I am actually kept quite busy supporting BYOB as it is with all the other experimental features (esp. nestable sprites). Once the Source Code of Scratch 1.4 is officially released I will also post the BYOB source, and will perhaps get some help from the community. Thank you for your feedback and for giving BYOB a try!

  5. Jens Mönig Says:

    minor bug fixes.

    I just fixed a couple of minor bugs relating to the BYOB error detection mechanism (the red outline around erroneous blocks, e.g. divisions by zero) and pushed the release no. to BYOB 2.0.1. Be sure to empty your browser’s cache before you download the zip file again, and to check if your downloaded version show this no. Thank you, Thilo, for notifying me about the bug in mention!

  6. Jens Mönig Says:

    update: bug fixes

    Hi all. I just fixed another round of bugs in BYOB and pushed the release number to BYOB 2.0.2. Be sure to empty your browser’s cache before you download the zip file again, and to check if your downloaded version shows this number.

    The following bugs have been fixed:

    (1) dragging a sprite in quarter-stage mode made it “pop” to full size
    (2) showing the value of custom reporter blocks defined for the stage by double clicking it raised an error notification. Thank you, Sophie, for cathing this bug!
    (3) numbers in a block specs raised an error. Thank you, Stefano, for reporting this bug!

    These were all rather nasty bugs, so I’d definitely recommend updating BYOB to the current version.

  7. Andres Claiman Says:

    Hi Jens!!!
    I´m a musician from Argentina
    I teach computer science applied to musical education (o someting like that… my english is very poor) in a music conservatory in Buenos Aires.
    I start using Scratch this year , and yesterday I discovered BYOB. Good Job!!!
    I have some trouble cheking out the nestable sprites thing. When I drop one icon sprite over the other they switch places… help me please!! ;)

    BTW I used some of your musical examples in my class . Thank you for that to.
    excuse my english again.
    Andres

  8. Andres Claiman Says:

    I just figure out the nestable sprites. thank´s

  9. Jens Mönig Says:

    Hi Andres,

    It’s wonderful that you’re using BYOB as well as Scratch’s musical side in Argentina, thanks for letting me know about it!

    If there is anything I can help you with regarding nestable sprites please do not hesitate to ask. You can also reach me at my first name at moenig dot org.

  10. A Scratch User Says:

    Hello, I think BYOB is a great program. However, I look for a “Connect to IP ()” block, so I can compile to exe, then people wouldn’t hack my game.
    Just see if that’s a good idea.

  11. Polprav Says:

    Hello from Russia!
    Can I quote a post in your blog with the link to you?

  12. R Says:

    Hello! I like it! I like how you can create blocks. Special i found: Scripts can turn smaller!