Build Your Own Blocks in Scratch

Building BlocksSo, you want to define your own procedures and functions in Scratch? Build your own blocks (BYOB :) )?

You might as well try this new experimental prototype I have been developing over the last weeks. You can download and read through an overview (pdf), or download the whole application (including the overview) and start playing with it right away.

This prototype lets you build your own custom blocks in Scratch using the standard Scratch blocks, as well as other blocks you defined elsewhere. You can create your own command blocks (procedures) and reporter blocks (functions), both regular (”round”) and boolean (”diamond”). You can specify for each block to be atomic (run at the speed of a single block) or interleafed. Your custom blocks are defined for each sprite and can be shared among projects together with the sprite they were created for. Oh, and you can even use a block within itself (recursion).

This prototype is very, very, experimental, so be prepared to encounter lots of bugs. I’d be very interested in feedback about your experiences and insights.

Enjoy!

-Jens

42 Responses to “Build Your Own Blocks in Scratch”

  1. Szocske Says:

    Hi,

    Great idea!
    This goes to the whole of Chirp btw.
    One possible issue with custom blocks I can think of:
    What if a composite block contains an infinite loop, but is set to execute in one step?

  2. Jens Mönig Says:

    Ah, good point! a forever block inside a custom block definition will always yield after each loop in the current prototype in order to prevent just that. There are other blocks, btw, which will also ignore the atomicity setting: All times blocks, e.g. wait, play note, glide etc.

  3. henley Says:

    the most awesome thing i think i have ever seen!

  4. Zam478 Says:

    Hello,
    Have you made any progress with that prototype you made earlier this year? I also have a bug, when I try to compile my *.sb 1.3 files, it will compile them, but when I launch it, that Lists IDE program comes up and says: Cannot read Header, please help!

  5. Zam478 Says:

    Oppz, sorry, I mean: Can Not Read: Bad Header. Again, sorry about that.

  6. Zam478 Says:

    Oh, I’m very sorry, I was just reading the forum for Chirp and I read what you said. I found the forums after I emailed this, I guess I probably should have down some more looking! I hope they post the source code soon. P.S. do you know a place to download Scratch 1.2?

  7. henley Says:

    where do you go to find out these things? where do you go to make these things?

    do you know where to find a source code for scratch 1.3?

  8. Jens Mönig Says:

    henley, I work on Scratch, but this is my personal project.

  9. dogbloos Says:

    this looks really cool but i dont understand at all how to use it…and i hate reading long instructions

  10. coolstuff Says:

    When I press the “compile” button, where does the .exe file go? I saved it under “projects” but I can only find the .sb file there. Any ideas?

    Also, in the compiled file, when I run the .exe, does the .exe file cause it to go directly into presentation mode or does the .sb file? Because if it is the .sb file, then it would work on Macs, too, as I understand it.

  11. Jens Mönig Says:

    Hi coolstuff,

    the compiled .exe file always goes into the documents folder. If the compilation succeeds, the documents folder should actually open automatically and display the result.

    It’s the .exe file in combination with a modified .image which causes the presentation mode behaviour. You’re right, of course, that it would be possible (and even rather easy) to do the same for Macs. But I’m afraid I can’t do it, because I don’t own one :-)

  12. coolstuff Says:

    Hi Jens,
    It doesn’t open the “My Documents” folder, nor does it appear to reside in the My Documents folder, as I did a search of the HD and no file appeared by the name I had saved it as, which was “blah.sb”, so I searched for “blah.exe” and nothing appeared. Any ideas? Thanks.

  13. coolstuff Says:

    Also, to run the “compiled” project on a mac, would I only need to open the modified .image file with the original .app Mac application of Scratch? Or are the other contents not actually visible in a folder, and if so, how would I get to them? I’m really interested in how this could work on a Mac…

  14. Jens Mönig Says:

    Hi coolstuff, you might have blank somewhere spaces in your filepath, that’s why the current compiler prototype might not work. I’ll try to fix this sometime soon. Let me also try to figure out something for a Mac…

  15. Zawicki1 Says:

    Do these work in sratch projects? can you give a link to a project?

  16. cds56 Says:

    Yes jens, the umm, compiled stuff doesnt go… andywhere….. does it go to the “My documents” Folder? Where? I m Stumped

  17. Jens Mönig Says:

    @Zawicki1: BYOB is a prototype to try out this idea of letting users build their own blocks in Scratch. It uses a file format which is incompatible to regular Scratch, so you cannot post projects made with BYOB to the Scratch website. But you can share them as .exe files.

    @cds56: The compiler still has some issues with pathnames containing blanks or spaces, so that might be the problem you’re observing. Thanks for informing me about this! I’ll look into this and try a fix sometime.

  18. cds56 Says:

    thats an odd problem, im renaming My Documents, to MyDocuments, would that work?

  19. john Says:

    how did you get the 1.3 sorce code?

  20. Jens Mönig Says:

    @cds56: I wouldn’t rename any system folders just yet. The output folder is usually not the problem, the input one is, though (the one where the source project is located). Hang on, I’m about to fix this for the next release!

    @john: I’m working on Scratch

  21. wordMan Says:

    I jest got this and it’s very cool!

  22. Tsomething Says:

    i have a problem…..
    i downloaded it but when i choose reporter or Boolean block it does not let me insert the answer into the report cavity at the bottom.

  23. Jens Mönig Says:

    Hi Tsomething,

    inserting something into the block editor’s “report” field sometimes takes a lot of fiddling around. I really ought to make that part better! Sometimes it works best if you drop the answer slightly to the left of the report-field onto the label.

  24. Tsomething Says:

    yes i figured that out now
    thanks!

  25. cds56 Says:

    Yes. And I have figured out that you cannot rename the folder anyways.

  26. Auron Says:

    The % block thing won’t work for my mum’s Vista.
    Is it a bug?

  27. Auron Says:

    Oh and it says Subscript is out of bounds

  28. spentec Says:

    neato!!!

  29. Billyedward Says:

    Sounds great! but i can’t find where to download it!

  30. Billyedward Says:

    BTW: henley, go to jens source project , it tells u how to get at the 1.3 source. NOT 1.3.1, though.

  31. Surfer123 Says:

    cool!

  32. billyedward Says:

    Hi, jens.
    I’m working on my own version of scratch (kinda like chirp), and am ready for the first release. But here’s the thing: when I call the “fillScreenOn” function, it does everything it’s supposed to, sets “scratchFrameMorph” to fill the screen, enters novice mode, etc. But here lies the problem. I can’t save the image file in this state, because I can’t access the world menu. If it isn’t too much trouble, how did you do this to save the final version of chirp?

  33. billyedward Says:

    Auron: if it says ’subscript is out of bounds’ it means that you tried to put too much into what is supposed to be a single line of text. To preserve memory, scratch wraps long strings onto other hidden lines; the subscript. However, there is a limit (bound) to how long the subscript can be. hope this helps!

  34. Jens Mönig Says:

    Hi billyedward,

    to save a “deployable” version of your own Scratch derivative, just select “save image in user mode” from the Extras-menu in the Source Code release, i.e. without switching to user mode first. I’m very curious about your work, which features did you add?

  35. BigFrog Says:

    Hi Jens
    First , I have to give my thanks for your release Scratch2exe.
    It give us lots of help.
    I am from Taiwan. My English is so bad, I try to make myself clear,
    If it is possible that you can develop another function, that we can let our projects to SWF?
    Sorry to ask for this.
    it will be great if you can give me a mail.
    bigfrog@bigfrog.com.tw

  36. abeair Says:

    Can I use this in 1.3.1 source?

  37. Jens Mönig Says:

    Hi BigFrog,
    converting Scratch projects to flash is currently not on my short-term agenda, sorry.

    Hi abeair,
    The BYOB image is currently pretty much “locked down”, preventing you from accessing the source code. I’m planning to release the BYOB source code after the next update or so (I’m in the process of adding some more features, like inter-sprite messages with parameters)

  38. billyedward Says:

    Hi, Jens, thanks!
    The reason that I didn’t notice that is that I wasn’t using the published code. However, I copied the code that that option runs, into a workspace, then ‘did it now’. It worked great, Thanks!
    My new features are pretty elementary:
    1. I added ‘factorial’ to the function block
    2. I brought back the old image effects.
    3. I added a ‘enter/exit compatible mode’ option to the shift+extras menu.
    4. When not in compatible mode, it saves a *.sc, instead of *.sb
    5. when not in compatible mode, two new reporter blocks appear:
    -hidden?
    -pen down?
    6. I changed all the spellings of ‘color’ to the proper english ‘colour’. (for compatibility, it can still read ‘color’ in the image effects)
    7. When you press shift while entering presentation mode, it doesn’t enter fullscreen.
    8. I also added to shift+extras a enter/exit full screen option. This is usually only done for presentation mode, but now you get more space to edit!
    9. pressing shift while changing pallette categories, or opening a project, makes the blocks darker. this increases contrast, aiding the visually impaired.
    10. there is a ‘enter/exit’ blind mode shift+extras option. this makes the menus bigger.
    11. I’ve brought back some of the working/useful obsolete blocks.
    12. I’m usre there’s more, which I’ve forgotten :)
    If you want to use any of my ideas for chirp- go ahead.

  39. Mike Says:

    How do I install

  40. Mike Says:

    Got it never mind

  41. billyedward Says:

    Hi, jens. Just wondering…
    the
    ^ self beep

  42. billyedward Says:

    Hi Jens-
    Another quick question:
    you know the
    ^ self beep
    command in squeak?
    I’ve tried to make a block in sound that does this, but when I run it, squeak entirely freezes.
    Do you know What’s going on?
    sorry about this,
    Thanks.