This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.
  • Index
  •  » Advanced Topics
  •  » ITopic: Helpful things to know when creating custom blocks in scratch

#1 2010-11-15 04:32:25

subzerostig
Scratcher
Registered: 2010-09-08
Posts: 100+

ITopic: Helpful things to know when creating custom blocks in scratch

This is a topic for people to help other people learn how to code blocks and to try to unsolve their problems if they get stuck.

It is not made for people to share blocks.

INDEX

1 How to get to the browser
2 The start of creating a block
2.1 how to find where to put it
3 how to create the block
3.1 Explanation of simple blocks
3.2 Explanation of more complex blocks
3.3 list of data inserters
3.4 The blocks type
3.5 Explanation of 3.6
3.6 How to create the broadcast
4 Programming it, where to program it
4.1 how to create the 'broadcast received' bit
4.2 List of symbols
4.3 coding it
5 How it works
6 Finish


1 How to get to the browser
Right now when you have opened the browser. (if you have not then this forum should be useful )

2 The start of creating a block
When creating a block. eg the showing? block you need to have several things.
First you need to put it in the right place. scriptablescratchmorph deals with stuff like control,operators,sound,variables and lists.
Scratchspritemorph deals with motion, pen, looks and sensing.


2.1 How to find where to put it
As the looks block would go in the looks section we go to scratchspritemorph(obviously, class, block specs,block specs).

We then find the code where the looks section is involved. this can be confusing, but all you need to do is to look at the text at the start of each bracket to see what its's called.

3 how to create the block
We would probably want this after the: 'hide' block so after the brackets add this:
('Showing?' #b #getHidden)

3.1 explanation of simple blocks
Now, the Showing block in between the single quotes, eg: 'Showing?' is what the block will be displayed as. You could change it to whatever you wanted and the block would stay the same.

3.2 explanation of more complex blocks
You may wonder about what blocks like: move ( ) steps. These have boxes that you can edit. You still add them in on the name of the block (we will worry about them later). In order to do this you nedd to put %+the corresponding letter. These are what you put other blocks in such as the boolean block: 'key ? pressed' into boolean spaces(the diamond ones) which would be inserted as %b


3.3 List of data inserters
List supplied by billyedward.

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 al

The main ones are:b,s and n
b creates the diamond to insert a boolean block
s creates the round block that you can enter numbers and text
n creates the round block that you can only enter numbers.

3.4 The blocks type
After the name of the block, we need to determine what type it will show up as.
You then need to add #+its type. So in order to create a boolean block we would add #b.
List supplied by LS97

-   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


Basically, a stack block needs #-
boolean, #b
and reporter, #r

3.5 explanation of 3.6
Then, the final bit is what its called when you will program it.
for example the showing block could be called getHidden

IMPORTANT
What you have just written is a bit like a broadcast, so the computer thinks, Oh look, the showing? block. It then sees we have written getHidden so  it broadcasts getHidden. Later on, we'll program the actual getHidden command so it actually does something. What you must remember though is that squeak(the browser that scratch is programmed in) is full of these commands. So everything you type in broadcasts something which decodes something and it's all complicated. The best way to learn this is through experience
IMPORTANT ANNOUNCEMENT OVER

3.6 How to create the broadcast
At the final bit add #+what you want to call it. I recomend something programmy like.
TIP: let the first word be all lowercase and the next all lowercase except the first letter which is capital.

They should be just one word. If you start programming with data inserters(or string inserters) then the message has to follow special rules. If People request then I will add that

Then, right click and click accept.

4 programming it, where to program it
Then go into instance.(if it says changes have not been saved, is it OK to cancel these changes then it means something is wrong with the block so It has not been saved)

Then go to the appropriate ops, if you can't find the category then try the other morphs(scriptablespritemorph, scriptablscratchmorph or if it is for the stage scriptablestagemorph). If you still can't find it then put it in other ops.(from this point on it can get really hard so use your judgement skills)

4.1 how to create the 'broadcast received bit'
Where it says:

message selector and argument names
"comment stating purpose of message"
|  temporary variable names  |
statements


replace this with that bit at the end of your block. in our case, getHidden(do not include#)

then right click and accept (you should notice a up arrow and the word self apear)

Complex alert: For some blocks, eg  move ( ) steps it gets more complex. for that block its code is forward: (tip, the : sign indicates something to be inserted) For this you would have to put Forward: t1   

t1 means variable no.1 . for blocks like the boolean block: ( ) = ( ) You would need 2 variables, t1 and t2

The code below then indicates what t1 or t2 is. (this sounds very complex but the best way to understand this is to move it into your comfort zone, just imagine t1 and t2 as fancy variable names.
complex bit over

4.2List of symbols
^=up arrow (Press shift 6)
[= square bracket (I think thats what its called)
|=shift and key left to space (needed for other blocks)

4.3 coding it
anyway, for our: showing block we need to put the code in so underneath the getHidden replace: up arrow self
with,

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

then right click and accept, the computer may alter spacing  between numbers, text and symbols.

Close down the browser and turn fill screen on.
5 how it works
I'm not an expert on coding, but what I do understand is how to do simple operations
When it is actually changing the sprite you add self
so the command for move is referencePosition (number)@(number)
so to get the sprite to move to a position with 2 variables t1 and t2 you would write
self referencePostition t1@t2

If you need futher help then ask someone like: pecola1,billyedward,sparks,LS97

Finish
IMPORTANT!

In order to save your work shift-click-r and click: turn fill screen on. Then do the same but click: save image for end user. (basically when you open scratch how it is now will be what its like when you open it up, so any project currently showing will be saved like that)

Congratulations!!! you have made a new block

Anything I have missed out on or any problems please ask and I (and the scratch community will try to help)

Last edited by subzerostig (2012-03-20 16:12:12)


There are 10 types of people people in this world, those that understand binary and those that do not: My latest Project: Present catcher V2                          06/12/2012

Offline

 

#2 2010-11-15 07:56:58

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

This is a really handy list, excellent work!

I've added it to the Advanced Topics "Helpful Topics" sticky.

Last edited by fullmoon (2010-11-15 16:03:13)


http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

#3 2010-11-17 15:30:47

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

You should mention that the attribute menu only works in the ([x position] of [Sprite1]) block.

Also, the sprite names menu works, but might bive you some difficulties.

Last edited by rubiks_cube_guy238 (2010-12-29 19:37:21)


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#4 2010-11-17 15:35:23

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

very nice! It seems to be really helpful!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#5 2010-12-08 15:27:48

subzerostig
Scratcher
Registered: 2010-09-08
Posts: 100+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

I am going to update soon!
big_smile


There are 10 types of people people in this world, those that understand binary and those that do not: My latest Project: Present catcher V2                          06/12/2012

Offline

 

#6 2011-01-26 06:47:21

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

Nice guide.
Can I suggest that you spice this up a little? Maybe add code boxes, colors, etc.
Also, make the link a link.
And for the list supplied by billyedward, %I is the midi list, %i is the 1/last/any of a list.
Are you going to put in the way to make the back arrow? It is _, which is shift + -.
Thanks!

Offline

 

#7 2011-01-26 11:06:43

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

...this isn't listed as an ITopic... have you just named it that?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#8 2011-01-26 11:09:00

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

sparks wrote:

...this isn't listed as an ITopic... have you just named it that?

fullmoon wrote:

This is a really handy list, excellent work!

I've added it to the Advanced Topics "Helpful Topics" sticky.

But I don't see it there either.

Offline

 

#9 2011-01-26 11:43:55

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

Oh , my bad, It's just called something else  tongue

coolstuff wrote:

Custom Blocks "Cheat Sheet", by subzerostig.
An extremely helpful reference for creating custom blocks.

tongue  Sorry!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#10 2011-01-26 15:06:03

subzerostig
Scratcher
Registered: 2010-09-08
Posts: 100+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

scimonster wrote:

Nice guide.
Can I suggest that you spice this up a little? Maybe add code boxes, colors, etc.
Also, make the link a link.
And for the list supplied by billyedward, %I is the midi list, %i is the 1/last/any of a list.
Are you going to put in the way to make the back arrow? It is _, which is shift + -.
Thanks!

yes, I'm working on it right now to make it easier to find what you want


There are 10 types of people people in this world, those that understand binary and those that do not: My latest Project: Present catcher V2                          06/12/2012

Offline

 

#11 2011-01-26 16:06:12

frowned
Scratcher
Registered: 2010-11-02
Posts: 42

Re: ITopic: Helpful things to know when creating custom blocks in scratch

anyone know how to iterate through sprites and check if they are clones from the stopALL method?

Offline

 

#12 2011-01-26 16:08:27

subzerostig
Scratcher
Registered: 2010-09-08
Posts: 100+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

updated!


There are 10 types of people people in this world, those that understand binary and those that do not: My latest Project: Present catcher V2                          06/12/2012

Offline

 

#13 2011-01-26 16:09:40

subzerostig
Scratcher
Registered: 2010-09-08
Posts: 100+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

frowned wrote:

anyone know how to iterate through sprites and check if they are clones from the stopALL method?

This topic is meant to be more for actually creating blocks not coding as much, maybe you could ask an expert?


There are 10 types of people people in this world, those that understand binary and those that do not: My latest Project: Present catcher V2                          06/12/2012

Offline

 

#14 2011-01-26 16:20:26

frowned
Scratcher
Registered: 2010-11-02
Posts: 42

Re: ITopic: Helpful things to know when creating custom blocks in scratch

ok fine making a new topic for it

Offline

 

#15 2011-02-14 19:10:56

Winkysquirt
Scratcher
Registered: 2010-07-30
Posts: 4

Re: ITopic: Helpful things to know when creating custom blocks in scratch

does it acually save the blocks cause i was coding for three hours once and i  closed out scratch... when  opened it up the blocks i made were deleted please reply

Offline

 

#16 2011-02-15 02:19:16

subzerostig
Scratcher
Registered: 2010-09-08
Posts: 100+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

It says at the end that you have to turn fill screen back on and the shift-click-R.
You then click save image for end user. It will then close scratch  and when you reopen the block will be there


There are 10 types of people people in this world, those that understand binary and those that do not: My latest Project: Present catcher V2                          06/12/2012

Offline

 

#17 2011-12-01 17:36:44

frowned
Scratcher
Registered: 2010-11-02
Posts: 42

Re: ITopic: Helpful things to know when creating custom blocks in scratch

Offline

 

#18 2011-12-01 18:43:05

G0D_M0D3
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: ITopic: Helpful things to know when creating custom blocks in scratch

Wow, that's very helpful. Helped me a lot on my way becoming a block devoloper.


I made a MC texture pack! Get it at planetminecraft!
http://i.imgur.com/0EG0u.png

Offline

 

#19 2012-03-05 18:56:00

Alexmon-Zeta
New Scratcher
Registered: 2012-03-05
Posts: 1

Re: ITopic: Helpful things to know when creating custom blocks in scratch

I don't understand.

Offline

 

#20 2012-03-06 05:22:48

sampleprojectmaker
New Scratcher
Registered: 2012-03-04
Posts: 1

Re: ITopic: Helpful things to know when creating custom blocks in scratch

lets test
[scratchblocks}
when gf clicked
go to [mouse-pointer v]
scratch is awesome!!
[/scratchblocks]

Offline

 

#21 2012-04-21 15:46:52

d610
Scratcher
Registered: 2011-01-22
Posts: 15

Re: ITopic: Helpful things to know when creating custom blocks in scratch

My block didn't work: ('hidden?' #b). How come it doesn't work? It is supposed to be a boolean "hidden?" block.  hmm


http://i46.tinypic.com/6rslr6.png

Offline

 
  • Index
  •  » Advanced Topics
  •  » ITopic: Helpful things to know when creating custom blocks in scratch

Board footer