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

#1 2010-04-18 04:48:02

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Cool custom blocks in Scratch

Note. IF THIS IS THE FIRST TIME YOU ARE READING THIS THREAD, READ THIS!
I am not doing any requests for blocks. This thread is now defunct, so please use it for information only and do not post requests. I will not answer any requests nor anymore clarifications. There's an amazing block library now where you can find many more blocks. If you have a good question about mods, you may post, but your question might not be answered.

Hey Scratchers!
Are you all wondering how to make your own blocks in Scratch using Squeak? Well then, you've come to the right place. This forum thread will include tutorials, links to other projects, and more!

The blocks are pretty much self-explanatory, so no need for a list of what they do. i'll start with the block-making right away.

Note for the lazy people: this tutorial aims to teach people to work in Squeak, not only to get the new blocks. So do not ask for my image file.

First, we have to open the system browser. Here's a tutorial for it:
T - Open Browser

Now, we're ready to start programming. From the browser, go to:
>Scratch-Objects
>ScriptableScratchMorph
>Click onto Class
>Scratch (or) BlockSpecs
>blockSpecks

Here we've got the main bit of blocks. it all looks very messy, so you can use the find option if you want to save your eyes when looking for a block. Now let's take a block to analyse: the yellow repeat(X) block.

('repeat %n'          c      doRepeat)

That's the specification for that block.
The block coding structure is as follows:

('repeat %n' #c #doRepeat 10)
the block is identified by the two brackets (blue).
the block text is in between apostrophes (black).
the block type identifier or block arguments follow a # sign (red).
the command also follows a # sign (green).
any additional arguments follow the command (purple).

the %n in the block is the input box, where the user can put the number. in fact, %n produces that round textbox where only numbers can be inserted. here's the full list:

Code:

a:  attribute of another sprite, such as X position or size.
b:  a boolean inserter
c:  a colour picker that shows the menu.
C:  a colour picker that doesn't
d:  the sprite direction menu/numerical inserter.
D:  the menu for midi drums
e:  The broadcast message menu
f:  math function menu (with sin, abs, etc.)
g:  menu for the different graphic effects.
h:  numerical sensor board selector menu
H:  boolean sensor board selector menu
i:  midi instrument menu/numerical inserter
k:  menu for the names of the different keys, used in the key sensor blocks.
l:  menu with the costume names of the given sprite.
L:  list name menu.
m:  sprite list
n:  numerical inserter
N:  note name menu/inserter
s:  string inserter
S:  sound selector menu
v:  variable labels menu
y:  menu used to delete either a number of the last value or all of a list.

Credit to billyedward for this list.

the repeat block, having to 'host' other blocks in it, is C shaped. that's why the block argument (above in red) is a c.
Here's a brief list of the different arguments:

Code:

#-   no arguments (command or 'stack' block)
#r   Reporter block (the round ones)
#b   boolean block (diamond shaped)
#c   C shaped block (like the forever block)
#t   Time block (like wait X secs)
#W   'when' hat block (obsolete)
#S   start button click hat block
#K   key-activated hat block
#E   event hat block (broadcast)
#s   special form (hard to code)

but it's not all that simple! now that we've got the block in the block palette, we need to give it the code it needs to perform the action. for this you need to go to 'instance', then to the appropriate 'ops'. there, after creating a method, you can add the code you need.
________
Now that you know a bit about the structure, we can move on quickly to the actual new blocks you saw at the beginning. I'm not going to add them into this post, it would be too long. you'll find the different blocks in different posts.
I hope you'll enjoy your new blocks!

Last edited by LS97 (2012-12-18 11:27:40)

Offline

 

#2 2010-04-18 07:22:38

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

The 'Get time/date' block

<get [date]>
<get [time]>
<get [hours]>
Here we go!
The get time/date block reports the time, date, hour, etc. without the user having to insert it manually.

Copy this line of code into a space between two blocks in the 'control' section of blockSpecs in ScriptableScratchMorph.

Code:

 ('get %s' #r #getTime: 'date')

Then go to the instance section, then to 'other ops' and replace the code of broadcast: with the following

Code:

getTime: t1 
    t1 = 'date' ifTrue: [^ Date today].
    t1 = 'short date' ifTrue: [^ Date today printFormat: #(1 2 3 $- 2 2 )].
    t1 = 'time' ifTrue: [^ Time now].
    t1 = 'seconds' ifTrue: [^ Time now seconds].
    t1 = 'minutes' ifTrue: [^ Time now minutes].
    t1 = 'hours' ifTrue: [^ Time now hours].
    t1 = 'day' ifTrue: [^ Date today weekday].
    t1 = 'help' ifTrue: [^ 'type date, short date, time, seconds, minutes, day, hours'].
    ^ 'Error!'

then right-click and click accept. type your initials and you're ready to use the new block!

NOTE:
There's a second, more advanced version of the block, with a drop-down menu instead of a string inserter, but it involves extra coding. If you are willing to take the challenge, please refer to this post. Thanks!

Last edited by LS97 (2012-12-19 06:02:34)

Offline

 

#3 2010-04-18 07:41:36

dav09
Scratcher
Registered: 2009-03-25
Posts: 1000+

Re: Cool custom blocks in Scratch

Nice tutorial!!!

Offline

 

#4 2010-04-18 08:12:44

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

dav09 wrote:

Nice tutorial!!!

Thanks! if you have any suggestions for some blocks, ask and i might be able to add them in this tutorial.

Offline

 

#5 2010-04-18 08:17:31

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

The 'showing?' block
This is an easy one. It gives a boolean response (True/False) of whether the sprite is showing or not.
Like before, copy this code into the 'looks' section of blockSpecs in ScratchSpriteMorph

Code:

('showing?' #b #getHidden)

then go to instance, 'looks ops' and replace the code in 'hide' with the code below (by the way, you're not deleting the hide block).

Code:

getHidden
    self isHidden = false ifTrue: [^ true].
    ^ false

Then right-click, clik accept and (maybe) type your initials. et voilà, you have your 'showing?' block up and ready.

Offline

 

#6 2010-04-18 08:18:24

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Cool custom blocks in Scratch

What does save stage area do? Does it take a pic of the stage?


http://i46.tinypic.com/dw7zft.png

Offline

 

#7 2010-04-18 08:30:11

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

SeptimusHeap wrote:

What does save stage area do? Does it take a pic of the stage?

yes, it does. it's really easy to make too. if you come back in 5 mins you'll find it up.

Offline

 

#8 2010-04-18 08:32:31

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Cool custom blocks in Scratch

OK. May we use it for our mod, Panther (I guess you've heard of it?)


http://i46.tinypic.com/dw7zft.png

Offline

 

#9 2010-04-18 08:34:37

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

The 'save stagearea to sprite' block

save stage area to sprite
I did this one on request of SeptimusHeap. it's maybe the easiest of the blocks. No coding needed, just add the block to the blockSpecs in ScratchSpriteMorph:

Code:

 ('save stage area to sprite' #- #grabFromScreen)

that's it! easy right?
PS. in case you didnt know, you have click accept.

Last edited by LS97 (2012-12-19 06:03:24)

Offline

 

#10 2010-04-18 08:35:52

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Cool custom blocks in Scratch

Permission...?


http://i46.tinypic.com/dw7zft.png

Offline

 

#11 2010-04-18 08:36:55

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Cool custom blocks in Scratch

Oh, may I have the ___ mouse down block, too?


http://i46.tinypic.com/dw7zft.png

Offline

 

#12 2010-04-18 08:38:31

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

SeptimusHeap wrote:

OK. May we use it for our mod, Panther (I guess you've heard of it?)

Well, i haven't heard of it to be honest, but the link in your sig helped. a lot. of course you may use it, as long as it's got the coding for it already in it (which scratch 1.3 and 1.4 does). i don't mean the coding i put up onthe forums but the one i refer to in the code. in other words, the 'grabFromScreen'.

anyway yes you may.

Offline

 

#13 2010-04-18 08:41:39

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Cool custom blocks in Scratch

You are now an official Panther contributer!


http://i46.tinypic.com/dw7zft.png

Offline

 

#14 2010-04-18 08:49:02

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

The mouse down block

<[left] mouse down?>
Another request of SeptimusHeap.
Put this code in both Sprite and Stage Morph blockSpecs in the sensing category:

Code:

 ('%s mouse down?' #b #mousePressed: 'left')

then into the instance, into ScriptableScratchMorph, and into 'sensing ops'.
replace the 'mousePressed' code with the one below.

Code:

mousePressed: t1 
    t1 = 'left' ifTrue: [^ Sensor redButtonPressed].
    t1 = 'right' ifTrue: [^ Sensor yellowButtonPressed].
    t1 = 'middle' ifTrue: [^ Sensor blueButtonPressed].
    t1 = 'any' ifTrue: [^ Sensor anyButtonPressed].
    t1 = 'left ' ifTrue: [^ Sensor redButtonPressed].
    t1 = 'right ' ifTrue: [^ Sensor yellowButtonPressed].
    t1 = 'middle ' ifTrue: [^ Sensor blueButtonPressed].
    t1 = 'any ' ifTrue: [^ Sensor anyButtonPressed].
    ^ Sensor redButtonPressed

Then click accept and it should be fine. you'll find the new block in the sensing category. you can put left, right, middle or any into the box and it'll give you the respective sensor button boolean.

Last edited by LS97 (2012-12-19 06:04:56)

Offline

 

#15 2010-04-18 08:51:31

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

SeptimusHeap wrote:

You are now an official Panther contributer!

wow, thanks for the honor! could you add me to the list on your site?

Last edited by LS97 (2010-04-18 08:56:38)

Offline

 

#16 2010-04-18 09:06:34

N-Wear
Scratcher
Registered: 2007-08-13
Posts: 100+

Re: Cool custom blocks in Scratch

Nice


If bread crumbs are better than nothing. And nothing is better than cheese cake. Then, bread crumbs are better than cheese cake!  smile
The following sentence is true. The previous sentence is false.  hmm                              Treat others the way you want to be treated!  big_smile

Offline

 

#17 2010-04-18 09:29:23

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Cool custom blocks in Scratch

LS97 wrote:

The 'Get time/date' block
http://www.freeimagehosting.net/uploads/209a5b329a.gif
Here we go!
The get time/date block reports the time, date, hour, etc. without the user having to insert it manually.

Copy this line of code into a space between two blocks in the 'control' section of blockSpecs in ScriptableScratchMorph.

Code:

 ('get %s' #r #getTime: 'date')

Then go to the instance section, then to 'other ops' and replace the code of broadcast: with the following

Code:

getTime: t1 
    t1 = 'date' ifTrue: [^ Date today].
    t1 = 'short date' ifTrue: [^ Date today printFormat: #(1 2 3 $- 2 2 )].
    t1 = 'time' ifTrue: [^ Time now].
    t1 = 'seconds' ifTrue: [^ Time now seconds].
    t1 = 'minutes' ifTrue: [^ Time now minutes].
    t1 = 'hours' ifTrue: [^ Time now hours].
    t1 = 'day' ifTrue: [^ Date today weekday].
    t1 = 'help' ifTrue: [^ 'type date, short date, time, seconds, minutes, day, hours'].
    ^ 'Error!'

then right-click and click accept. type your initials and you're ready to use the new block!

Thats a brillant idea!


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#18 2010-04-18 09:37:36

Keba
Scratcher
Registered: 2010-04-16
Posts: 9

Re: Cool custom blocks in Scratch

Hi there,

Is there a way to create using new blocks using BYOB? I cannot exit fullscreen in BYOB because there is no 'r' in the title bar...

Offline

 

#19 2010-04-18 09:41:26

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Cool custom blocks in Scratch

Keba wrote:

Hi there,

Is there a way to create using new blocks using BYOB? I cannot exit fullscreen in BYOB because there is no 'r' in the title bar...

the source code version of BYOB will be coming out sometime in august, these types of custom blocks aren't possible in BYOB. If you use Scratch or the sourcecode for Scratch then you can make custom blocks like these.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#20 2010-04-18 09:44:03

Keba
Scratcher
Registered: 2010-04-16
Posts: 9

Re: Cool custom blocks in Scratch

Hm, so there is now way of combining own blocks (eg a "clone block hack") and BYOB togehter? Both hack into the image files, don`t they? So way cant I edit the BYOB`s image file and put some nice blocks into it?

And why is there no source code release of BYOB yet? That sucks, too.

Offline

 

#21 2010-04-18 09:46:58

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Cool custom blocks in Scratch

Keba wrote:

Hm, so there is now way of combining own blocks (eg a "clone block hack") and BYOB togehter? Both hack into the image files, don`t they? So way cant I edit the BYOB`s image file and put some nice blocks into it?

And why is there no source code release of BYOB yet? That sucks, too.

Go ask Jens if there is a way of editing the imagefile, but he said that he removed the Editor from BYOB, I geuss so people couldn't steal the BYOB interface


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#22 2010-04-18 10:01:48

Sperry
Scratcher
Registered: 2010-03-09
Posts: 500+

Re: Cool custom blocks in Scratch

Great! I like it! One suggestion for your mousePressed block. I would suggest
^ false
instead of
^ Sensor redButtonPressed

If it even got as far as the last part, it should return false since it doesn't know what your talking about, why test some stuff that is jargon?

Last edited by Sperry (2010-04-18 10:02:12)


http://img709.imageshack.us/img709/3252/gobanim2.gifhttp://ls.gd/bo

Offline

 

#23 2010-04-18 10:16:06

Aidan
Scratcher
Registered: 2007-06-15
Posts: 1000+

Re: Cool custom blocks in Scratch

I have another problem. How do I 'save' the changes?

Offline

 

#24 2010-04-18 11:39:55

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

Aidan wrote:

I have another problem. How do I 'save' the changes?

that's something i didnt include in my tutorial, thanks for reminding me!
Shift-click the R again, and click 'save image for end-user'. then click yes.

Offline

 

#25 2010-04-18 11:42:10

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

Sperry wrote:

Great! I like it! One suggestion for your mousePressed block. I would suggest
^ false
instead of
^ Sensor redButtonPressed

If it even got as far as the last part, it should return false since it doesn't know what your talking about, why test some stuff that is jargon?

I understand what you mean, but i thought of the lazy people who don't want to enter anything and have it like the default block straight away. what use would it be anyway if it returns false each time?

Offline

 

Board footer