Discuss Scratch
- Gnome_Pal
- Scratcher
64 posts
Define Blocks
I NEED SO MUCH HELP WITH THESE DEFINE BLOCKS THAT APPEAR WHEN YOU MAKE A BLOCK!
Hello!
I am Gnome_Pal, but you can call me Gnome!
Here's some info on me:
- I'm an Aquarius: Feb. 16th
- I <3 code, duh
- You can address me by She/Her
“Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.” - Thomas Edison
- awesome-llama
- Scratcher
1000+ posts
Define Blocks
Take a look at the Scratch Wiki article. It explains it in a bit of detail: https://en.scratch-wiki.info/wiki/My_Blocks
My blocks have all sorts of uses. They can act like broadcasts, but they can also be used to simplify code or allow for better organisation.
You could think of the blocks as custom blocks you can program to do specific things.
Say I have this script:
There is a bunch of code that is repeating. Instead, we could put the repeating part in to a custom block:
See how the code is so much simpler and adjustable? Imagine if the scripts were larger. This method could be so much less code.
My blocks have all sorts of uses. They can act like broadcasts, but they can also be used to simplify code or allow for better organisation.
You could think of the blocks as custom blocks you can program to do specific things.
Say I have this script:
when green flag clicked
forever
if <key [left arrow v] pressed?> then
move (-5) steps
change [color v] effect by (-10)
next costume
end
if <key [right arrow v] pressed?> then
move (-5) steps
change [color v] effect by (10)
next costume
end
end
There is a bunch of code that is repeating. Instead, we could put the repeating part in to a custom block:
when green flag clicked
forever
if <key [left arrow v] pressed?> then
move (-5)::custom // the blocks are supposed to be pink
if <key [right arrow v] pressed?> then
move (5)::custom
end
end
define move (amount)::#FF6680
move (amount) steps
change [color v] effect by ((2) * (amount))
next costume
See how the code is so much simpler and adjustable? Imagine if the scripts were larger. This method could be so much less code.
Last edited by awesome-llama (March 29, 2021 13:33:58)
- deck26
- Scratcher
1000+ posts
Define Blocks
Have you read the wiki page on custom blocks? https://en.scratch-wiki.info/wiki/My_Blocks
What are you trying to achieve?
What are you trying to achieve?
- LittleTheRabbit
- Scratcher
74 posts
Define Blocks
I NEED SO MUCH HELP WITH THESE DEFINE BLOCKS THAT APPEAR WHEN YOU MAKE A BLOCK!
I believe I can help you: A define block is a block that you can make a custom code in, but you can use it in a singular block. But, in order for the block to work, you will need to put in valid code.
————————————————————————————————————————————————————————–
Hey! I'm LittleTheRabbit!
funny kid/coder with the funny!
- UniversalCoder13
- Scratcher
11 posts
Define Blocks
when green flag clicked
define ("glitch")
repeat (3)
repeat (10)
change [pixelate v] effect by (25)
change [ghost v] effect by (10)
wait (0.1) secs
end
end
- Gnome_Pal
- Scratcher
64 posts
Define Blocks
thx but thats not really what i meanI NEED SO MUCH HELP WITH THESE DEFINE BLOCKS THAT APPEAR WHEN YOU MAKE A BLOCK!
I believe I can help you: A define block is a block that you can make a custom code in, but you can use it in a singular block. But, in order for the block to work, you will need to put in valid code.
What i really want to know is that how do you use them?
Hello!
I am Gnome_Pal, but you can call me Gnome!
Here's some info on me:
- I'm an Aquarius: Feb. 16th
- I <3 code, duh
- You can address me by She/Her
“Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.” - Thomas Edison
- Gnome_Pal
- Scratcher
64 posts
Define Blocks
Like do you need to tell what the specific block does?
Last edited by Gnome_Pal (March 29, 2021 17:27:45)
Hello!
I am Gnome_Pal, but you can call me Gnome!
Here's some info on me:
- I'm an Aquarius: Feb. 16th
- I <3 code, duh
- You can address me by She/Her
“Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.” - Thomas Edison
- --VirtualLogic--
- Scratcher
100+ posts
Define Blocks
Like do you need to tell what the specific block does?
Hello, there. My blocks can be used to achieve something like a broadcast, but can also have inputs and booleans in it. The Define block is where you can put all of your code, along with dragging the pink inputs and booleans. Here is an example
when green flag clicked
forever
rotate 360:: #ff00ff stack
end
define rotate 360:: #ff00ff
repeat until <(direction) > [89]>
turn cw (15) degrees
end
Last edited by --VirtualLogic-- (March 29, 2021 17:40:42)
(∩ ∩)::#FFA500 // This is smileblock, he protects my signature from evil kumquats (and of course grapes)
Hello, I'm logic, a programmer and digital artist that enjoys using Scratch in his free time.
I'm also very uncreative when coming up with names. (See scratchblocks above)
- Gnome_Pal
- Scratcher
64 posts
Define Blocks
AAAAAAAAAAAAAAA
Hello!
I am Gnome_Pal, but you can call me Gnome!
Here's some info on me:
- I'm an Aquarius: Feb. 16th
- I <3 code, duh
- You can address me by She/Her
“Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.” - Thomas Edison
- LittleTheRabbit
- Scratcher
74 posts
Define Blocks
thx but thats not really what i meanI NEED SO MUCH HELP WITH THESE DEFINE BLOCKS THAT APPEAR WHEN YOU MAKE A BLOCK!
I believe I can help you: A define block is a block that you can make a custom code in, but you can use it in a singular block. But, in order for the block to work, you will need to put in valid code.
What i really want to know is that how do you use them?
You use Define Blocks by putting code under the little hat shaped part, and then once the code is under that, drag the actual block in the “My Blocks” section into your own code, (not under the hat shaped block).
For example:
define TEST
say [test!] for (2) secs
when green flag clicked
(here you would put your custom block.)
stop [this script]
————————————————————————————————————————————————————————–
Hey! I'm LittleTheRabbit!
funny kid/coder with the funny!
- LittleTheRabbit
- Scratcher
74 posts
Define Blocks
The top script in my example above shows the define block.
————————————————————————————————————————————————————————–
Hey! I'm LittleTheRabbit!
funny kid/coder with the funny!
- Gnome_Pal
- Scratcher
64 posts
Define Blocks
this is funny and I'M STILL CONFUSED (sorry if i'm making you stressed)thx but thats not really what i meanI NEED SO MUCH HELP WITH THESE DEFINE BLOCKS THAT APPEAR WHEN YOU MAKE A BLOCK!
I believe I can help you: A define block is a block that you can make a custom code in, but you can use it in a singular block. But, in order for the block to work, you will need to put in valid code.
What i really want to know is that how do you use them?
You use Define Blocks by putting code under the little hat shaped part, and then once the code is under that, drag the actual block in the “My Blocks” section into your own code, (not under the hat shaped block).
For example:define TEST
say [test!] for (2) secswhen green flag clicked
(here you would put your custom block.)
stop [this script]
Hello!
I am Gnome_Pal, but you can call me Gnome!
Here's some info on me:
- I'm an Aquarius: Feb. 16th
- I <3 code, duh
- You can address me by She/Her
“Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.” - Thomas Edison
- LittleTheRabbit
- Scratcher
74 posts
Define Blocks
You aren't, but probably watch a youtube tutorial.this is funny and I'M STILL CONFUSED (sorry if i'm making you stressed)thx but thats not really what i meanI NEED SO MUCH HELP WITH THESE DEFINE BLOCKS THAT APPEAR WHEN YOU MAKE A BLOCK!
I believe I can help you: A define block is a block that you can make a custom code in, but you can use it in a singular block. But, in order for the block to work, you will need to put in valid code.
What i really want to know is that how do you use them?
You use Define Blocks by putting code under the little hat shaped part, and then once the code is under that, drag the actual block in the “My Blocks” section into your own code, (not under the hat shaped block).
For example:define TEST
say [test!] for (2) secswhen green flag clicked
(here you would put your custom block.)
stop [this script]
————————————————————————————————————————————————————————–
Hey! I'm LittleTheRabbit!
funny kid/coder with the funny!
- deck26
- Scratcher
1000+ posts
Define Blocks
You'd want to use a custom block for various reasons. One example might be where you just want a bit of code to run faster. So if you were sorting a list, for example, it should be faster in a custom block with no screen refresh. Similarly if you want to draw a grid on screen as I do here https://scratch.mit.edu/projects/55182496/ or any other pen project needing a lot of redrawing.
Note in the custom block in my draw grid example I use parameters which means I can tell it to draw a grid with so many rows, so many columns and how wide apart the lines are. I could use the same custom block multiple times to draw several grids by just calling the block with different numbers - no need to set certain variables the appropriate values as i would have to with a broadcast.
That's just a simple example but may help you understand a bit more.
Note in the custom block in my draw grid example I use parameters which means I can tell it to draw a grid with so many rows, so many columns and how wide apart the lines are. I could use the same custom block multiple times to draw several grids by just calling the block with different numbers - no need to set certain variables the appropriate values as i would have to with a broadcast.
That's just a simple example but may help you understand a bit more.
- Gnome_Pal
- Scratcher
64 posts
Define Blocks
https://scratch.mit.edu/projects/55182496/ or any other pen project needing a lot of redrawing.Okay so, now i can understand a bit more but i still don't understand like what do they mean by “define” and how do you define your custom blocks? You'd want to use a custom block for various reasons. One example might be where you just want a bit of code to run faster. So if you were sorting a list, for example, it should be faster in a custom block with no screen refresh. Similarly if you want to draw a grid on screen as I do here
Note in the custom block in my draw grid example I use parameters which means I can tell it to draw a grid with so many rows, so many columns and how wide apart the lines are. I could use the same custom block multiple times to draw several grids by just calling the block with different numbers - no need to set certain variables the appropriate values as i would have to with a broadcast.
That's just a simple example but may help you understand a bit more.
Hello!
I am Gnome_Pal, but you can call me Gnome!
Here's some info on me:
- I'm an Aquarius: Feb. 16th
- I <3 code, duh
- You can address me by She/Her
“Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.” - Thomas Edison
- bluedragon8633
- Scratcher
1000+ posts
Define Blocks
Okay so, now i can understand a bit more but i still don't understand like what do they mean by “define” and how do you define your custom blocks?
The most basic use for custom blocks is as a shortcut. Here's an example:
when green flag clickedThat drew two squares. But I had to copy and paste the same “draw a square” code twice- that's excessive code!
go to x: (0) y: (0)
pen down
change x by (10)
change y by (10)
change x by (-10)
change y by (-10)
pen up
go to x: (25) y: (50)
pen down
change x by (10)
change y by (10)
change x by (-10)
change y by (-10)
pen up
Compare that to this:
when green flag clicked
go to x: (0) y: (0)
draw square :: custom
go to x: (25) y: (50)
draw square :: custom
But now you need a way for your project to know what “draw square” means. That's where the Define block comes in.
define draw square
pen down
change x by (10)
change y by (10)
change x by (-10)
change y by (-10)
pen up
Now, you only need to have one copy of the “draw a square” code! Hope this helps.
Game with No Sprites: https://scratch.mit.edu/projects/710922832/
Riddle School 5- Tile Puzzle 1: https://scratch.mit.edu/projects/625744508/
RIP Adobe Flash Player
Yokan is coming.
- Gnome_Pal
- Scratcher
64 posts
Define Blocks
Wait, your only telling me about the custom blocks not the define blocksOkay so, now i can understand a bit more but i still don't understand like what do they mean by “define” and how do you define your custom blocks?
The most basic use for custom blocks is as a shortcut. Here's an example:when green flag clickedThat drew two squares. But I had to copy and paste the same “draw a square” code twice- that's excessive code!
go to x: (0) y: (0)
pen down
change x by (10)
change y by (10)
change x by (-10)
change y by (-10)
pen up
go to x: (25) y: (50)
pen down
change x by (10)
change y by (10)
change x by (-10)
change y by (-10)
pen up
Compare that to this:when green flag clicked
go to x: (0) y: (0)
draw square :: custom
go to x: (25) y: (50)
draw square :: custom
But now you need a way for your project to know what “draw square” means. That's where the Define block comes in.define draw square
pen down
change x by (10)
change y by (10)
change x by (-10)
change y by (-10)
pen up
Now, you only need to have one copy of the “draw a square” code! Hope this helps.
Hello!
I am Gnome_Pal, but you can call me Gnome!
Here's some info on me:
- I'm an Aquarius: Feb. 16th
- I <3 code, duh
- You can address me by She/Her
“Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.” - Thomas Edison
- Gnome_Pal
- Scratcher
64 posts
Define Blocks
say [Hi!] for (2) secs
[Jump for (10) secs]
define Jump for (0) secs
Last edited by Gnome_Pal (April 2, 2021 21:10:35)
Hello!
I am Gnome_Pal, but you can call me Gnome!
Here's some info on me:
- I'm an Aquarius: Feb. 16th
- I <3 code, duh
- You can address me by She/Her
“Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.” - Thomas Edison
- bluedragon8633
- Scratcher
1000+ posts
Define Blocks
Did you not read what I wrote? Wait, your only telling me about the custom blocks not the define blocks
But now you need a way for your project to know what “draw square” means. That's where the Define block comes in.define draw square
pen down
change x by (10)
change y by (10)
change x by (-10)
change y by (-10)
pen up
The define block is where you put the code for the custom blocks, so that when you activate the custom block, it does whatever code is in the define block.
Game with No Sprites: https://scratch.mit.edu/projects/710922832/
Riddle School 5- Tile Puzzle 1: https://scratch.mit.edu/projects/625744508/
RIP Adobe Flash Player
Yokan is coming.
- Gnome_Pal
- Scratcher
64 posts
Define Blocks
Ok, so you just put what you want custom block to do in there?Did you not read what I wrote? Wait, your only telling me about the custom blocks not the define blocksBut now you need a way for your project to know what “draw square” means. That's where the Define block comes in.define draw square
pen down
change x by (10)
change y by (10)
change x by (-10)
change y by (-10)
pen up
The define block is where you put the code for the custom blocks, so that when you activate the custom block, it does whatever code is in the define block.
—————————————–
when green flag clicked
say [Hi!] for (2) secs
sing :: custom
define sing
if <(backdrop name) = [backdrop1]> then
play sound [Opera music v] until done
end
Last edited by Gnome_Pal (April 3, 2021 01:11:05)
Hello!
I am Gnome_Pal, but you can call me Gnome!
Here's some info on me:
- I'm an Aquarius: Feb. 16th
- I <3 code, duh
- You can address me by She/Her
“Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.” - Thomas Edison