Discuss Scratch

justin_lau
Scratcher
43 posts

More Blocks?

What are the uses of the more blocks?
turkey3_test
Scratcher
1000+ posts

More Blocks?

More blocks are custom blocks, and the best way to explain it is visually.
define jump //name of the block
repeat (10)
change y by (5)
end
repeat (10)
change y by (-10)
end

when gf clicked
jump //you can do this instead of writing the whole script above
You should also check out on the Wiki Custom Blocks.
justin_lau
Scratcher
43 posts

More Blocks?

turkey3_test wrote:

More blocks are custom blocks, and the best way to explain it is visually.
define jump //name of the block
repeat (10)
change y by (5)
end
repeat (10)
change y by (-10)
end

when gf clicked
jump //you can do this instead of writing the whole script above
You should also check out on the Wiki Custom Blocks.

So, how is it different from Broadcast blocks?
turkey3_test
Scratcher
1000+ posts

More Blocks?

justin_lau wrote:

turkey3_test wrote:

More blocks are custom blocks, and the best way to explain it is visually.
define jump //name of the block
repeat (10)
change y by (5)
end
repeat (10)
change y by (-10)
end

when gf clicked
jump //you can do this instead of writing the whole script above
You should also check out on the Wiki Custom Blocks.

So, how is it different from Broadcast blocks?
There are a few differences. What I have above is only a simple type. Parameters can be inserted into custom blocks as such:
define jump (height) pixels
repeat (round ((height) / (5)))
change y by (5)
end
repeat (round ((height) / (5)))
change y by (-5)
end

when gf clicked
jump (50) pixels
jump (100) pixels
jump (30) pixels
So you can customize the value by changing the parameters. Also, only one broadcast received script can be running in the sprite at once, but with custom blocks the same custom block, or “procedure”, can run in many scripts simultaneously,
justin_lau
Scratcher
43 posts

More Blocks?

I

turkey3_test wrote:

justin_lau wrote:

turkey3_test wrote:

More blocks are custom blocks, and the best way to explain it is visually.
define jump //name of the block
repeat (10)
change y by (5)
end
repeat (10)
change y by (-10)
end

when gf clicked
jump //you can do this instead of writing the whole script above
You should also check out on the Wiki Custom Blocks.

So, how is it different from Broadcast blocks?
There are a few differences. What I have above is only a simple type. Parameters can be inserted into custom blocks as such:
define jump (height) pixels
repeat (round ((height) / (5)))
change y by (5)
end
repeat (round ((height) / (5)))
change y by (-5)
end

when gf clicked
jump (50) pixels
jump (100) pixels
jump (30) pixels
So you can customize the value by changing the parameters. Also, only one broadcast received script can be running in the sprite at once, but with custom blocks the same custom block, or “procedure”, can run in many scripts simultaneously,

I still don't get it
ErnieParke
Scratcher
1000+ posts

More Blocks?

@justin_lau:
It's okay. When I first learned about parameters, I didn't get it as well.

Now, let's take a look back at Turkey3's script (with a few touches):

define jump (height) pixels
repeat (height)
change y by (1)
end
repeat (height)
change y by (-1)
end

when gf clicked
jump (50) pixels

The variable height is just like any variable. When you say [jump (50) pixels] you're setting height to 50. When you say [jump (77) pixels], you're setting it to 77. Do you see?

When you say [jump (50) pixels], you're also running the code beneath the block. So when you say [jump (50) pixels], you're saying jump up 50 pixels! That's done by:

repeat (50)
change y by (1)
end
repeat (50)
change y by (-1)
end

Where did the height variable go? When we ran [jump (50) pixels], we set height to 50. So it's in the script. Then we change y by 50, and change it by -50 to finish our jump.

Any questions?

Explaining,

ErnieParke
1234abcdcba4321
Scratcher
1000+ posts

More Blocks?

Also, blocks don't carry between sprites. (I wish they did…)
justin_lau
Scratcher
43 posts

More Blocks?

Th

ErnieParke wrote:

@justin_lau:
It's okay. When I first learned about parameters, I didn't get it as well.

Now, let's take a look back at Turkey3's script (with a few touches):

define jump (height) pixels
repeat (height)
change y by (1)
end
repeat (height)
change y by (-1)
end

when gf clicked
jump (50) pixels

The variable height is just like any variable. When you say [jump (50) pixels] you're setting height to 50. When you say [jump (77) pixels], you're setting it to 77. Do you see?

When you say [jump (50) pixels], you're also running the code beneath the block. So when you say [jump (50) pixels], you're saying jump up 50 pixels! That's done by:

repeat (50)
change y by (1)
end
repeat (50)
change y by (-1)
end

Where did the height variable go? When we ran [jump (50) pixels], we set height to 50. So it's in the script. Then we change y by 50, and change it by -50 to finish our jump.

Any questions?

Explaining,

ErnieParke
Thks
ErnieParke
Scratcher
1000+ posts

More Blocks?

@justin_lau:
You're welcome!

Always happy,

ErnieParke
justin_lau
Scratcher
43 posts

More Blocks?

Powered by DjangoBB