Discuss Scratch
- Discussion Forums
- » Suggestions
- » custom block with return value
- ScratchinJoJo
- Scratcher
100+ posts
custom block with return value
I would like to see a new feature in scratch.
A custom block should be able to return a value.
This can be done to do for example calculations. You can do the calculation in a new define block, and when you have the value, you can add a return block to return a value, which can be used in your main function
a little example:
Like this, scratch would be way flexible, and you would be able
A custom block should be able to return a value.
This can be done to do for example calculations. You can do the calculation in a new define block, and when you have the value, you can add a return block to return a value, which can be used in your main function
a little example:
define CheckWhichIsTheMost(num1)(num2)
if <[num1] > [num2]> then
return(num1)
else
return(num2)
end
when green flag clicked
set [var] to [(CheckWhichIsTheMost(365)(954))]
Like this, scratch would be way flexible, and you would be able
- ScratchinJoJo
- Scratcher
100+ posts
custom block with return value
(oops posted too early, so let's continue the post)
Like this, scratch would be way more flexible, and you would be able to do more with less code.
It also makes your code a lot cleaner, and more readable.
You can re-use a lot of code without having to copy-paste and the best is, you can do this with input so you just enter the formula in the define block,
and then when you use the formula you can fill in the values. (this can off course also be used for a lot of other stuff than math formulas )
I hope this get's added, it would really be a great improvement
Like this, scratch would be way more flexible, and you would be able to do more with less code.
It also makes your code a lot cleaner, and more readable.
You can re-use a lot of code without having to copy-paste and the best is, you can do this with input so you just enter the formula in the define block,
and then when you use the formula you can fill in the values. (this can off course also be used for a lot of other stuff than math formulas )
I hope this get's added, it would really be a great improvement
- Scratchifier
- Scratcher
1000+ posts
custom block with return value
No support - and here's why:
In “Exhibit A”, let's pretend that “Variable” is a public variable. After the Which Value Is Higher block runs, “Variable” will be set to “15”. Now, this is universal, unlike regular programming.
Now, still in “Exhibit A”, let's say that “Variable” is a private variable. After that script runs, “Variable” will be set to “15” for only the main sprite. Any values from clones of that sprite will remain unchanged. Of course, you're likely not going to make 10 clones before that runs, since it's connected to a green flag clicked block, but that's beside the point.
In “Exhibit B”, if “Variable” is a public variable, it will do the same thing as Exhibit A's public variable did (set “Variable” to 15 again, since it's just going to go for the highest value)
In “Exhibit B” with a private “Variable”, only that specific clone's value of “Variable” will change.
Now sorry if you already knew all of this with Scratch, but considering that you can practically mimic the return value with other scripts like shown above, I don't support.
In “Exhibit A”, let's pretend that “Variable” is a public variable. After the Which Value Is Higher block runs, “Variable” will be set to “15”. Now, this is universal, unlike regular programming.
Now, still in “Exhibit A”, let's say that “Variable” is a private variable. After that script runs, “Variable” will be set to “15” for only the main sprite. Any values from clones of that sprite will remain unchanged. Of course, you're likely not going to make 10 clones before that runs, since it's connected to a green flag clicked block, but that's beside the point.
In “Exhibit B”, if “Variable” is a public variable, it will do the same thing as Exhibit A's public variable did (set “Variable” to 15 again, since it's just going to go for the highest value)
In “Exhibit B” with a private “Variable”, only that specific clone's value of “Variable” will change.
Now sorry if you already knew all of this with Scratch, but considering that you can practically mimic the return value with other scripts like shown above, I don't support.
- ScratchinJoJo
- Scratcher
100+ posts
custom block with return value
Now sorry if you already knew all of this with Scratch, but considering that you can practically mimic the return value with other scripts like shown above, I don't support.
Yes, that's true. I did know that this was possible, but your code looks way less clean.
If you would have a lot of such functions, you would need to create a lot of variables (that you have to re-create in every sprite you use the functions).
I think it's not good to make a new variable for each function you make.
Your code is also less readable, and the thing that i like about scratch, is that it's very readable (except in this case).
It would be a lot cleaner with return, and also a lot easier. The mimicking trick looks a bit hackish in my eyes.
- ChocolatePi
- Scratcher
1000+ posts
custom block with return value
That is much less efficient and readable. It would be much more appealing No support - and here's why:and would teach kids more programming concepts if we'd introduce this. After all, Scratch is about teaching programming.
In “Exhibit A”, let's pretend that “Variable” is a public variable. After the Which Value Is Higher block runs, “Variable” will be set to “15”. Now, this is universal, unlike regular programming.
Now, still in “Exhibit A”, let's say that “Variable” is a private variable. After that script runs, “Variable” will be set to “15” for only the main sprite. Any values from clones of that sprite will remain unchanged. Of course, you're likely not going to make 10 clones before that runs, since it's connected to a green flag clicked block, but that's beside the point.
In “Exhibit B”, if “Variable” is a public variable, it will do the same thing as Exhibit A's public variable did (set “Variable” to 15 again, since it's just going to go for the highest value)
In “Exhibit B” with a private “Variable”, only that specific clone's value of “Variable” will change.
Now sorry if you already knew all of this with Scratch, but considering that you can practically mimic the return value with other scripts like shown above, I don't support.
Support, although this has been suggested before in a much larger suggestion: Better Custom Blocks
- davidovski
- Scratcher
86 posts
custom block with return value
i was just about to make a suggestion about this
—————————————————–
at least somthing like this: (may not look exactly like it should…)\
define
—————————————————–
at least somthing like this: (may not look exactly like it should…)\
define
when green flag clicked
say (addedOne(10))
define addedOne (number)
return ((number) + (1))
- ChocolatePi
- Scratcher
1000+ posts
custom block with return value
By the way, the “return” block should look like this:
return [] :: custom cap // for string reporters
return () :: custom cap // for number reporters
return <> :: custom cap // for boolean reporters
- FalconGunner99
- Scratcher
1000+ posts
custom block with return value
Yeah I support the idea of adding custom reporters, it's been suggested many times before though, and the ST hasn't said much
; Oh this? This is just my semicolon. I got it a long time ago, it's quite innocuous. Don't worry about it.
You —> http://i.imgur.com/iVHfwLc.gifv
- DaSpudLord
- Scratcher
1000+ posts
custom block with return value
define custom block//The c-loop would be part of this hat block.Support.
::custom cstart
return []::cend
| Primary Target | Fireworks Show! Wheel of Fortune || Block Buster ||||| Shut the Box ||||||||| Surf's Up! |||||
U^ェ^U::motion//This is Blocky. He lives in my signature. He is a trained attack block. He protects my siggy from kumquats.
- whiskey0705
- New Scratcher
1 post
custom block with return value
define custom block//The c-loop would be part of this hat block.Support.
::custom cstart
return []::cend
hi, DaSpudLord!
Could you tell me where can I get the red ‘return’ brick? I didn't see any red bricks in my script area.
thanks in advance.
- DaEpikDude
- Scratcher
1000+ posts
custom block with return value
I believe custom reporters are confirmed to be coming in 3.0.define custom block//The c-loop would be part of this hat block.Support.
::custom cstart
return []::cend
hi, DaSpudLord!
Could you tell me where can I get the red ‘return’ brick? I didn't see any red bricks in my script area.
thanks in advance.
Also, just type in the block you want, and it'll be red if it doesn't exist and there's no colour specified.
And all the world over, each nation's the same,
They've simply no notion of playing the game.
They argue with umpires, they cheer when they've won,
And they practice beforehand, which ruins the fun!
- Charles12310
- Scratcher
1000+ posts
custom block with return value
I'm confused, but the reason why I do not think this should be added is because blocks can't report values unless with variables. No support - and here's why:
In “Exhibit A”, let's pretend that “Variable” is a public variable. After the Which Value Is Higher block runs, “Variable” will be set to “15”. Now, this is universal, unlike regular programming.
Now, still in “Exhibit A”, let's say that “Variable” is a private variable. After that script runs, “Variable” will be set to “15” for only the main sprite. Any values from clones of that sprite will remain unchanged. Of course, you're likely not going to make 10 clones before that runs, since it's connected to a green flag clicked block, but that's beside the point.
In “Exhibit B”, if “Variable” is a public variable, it will do the same thing as Exhibit A's public variable did (set “Variable” to 15 again, since it's just going to go for the highest value)
In “Exhibit B” with a private “Variable”, only that specific clone's value of “Variable” will change.
Now sorry if you already knew all of this with Scratch, but considering that you can practically mimic the return value with other scripts like shown above, I don't support.
A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
- avreal
- New Scratcher
1 post
custom block with return value
It's messy
just because I can't create blocks like Square, Length, CalcSpeed, etc. and I do not want to create mess of temporary variables — local for spirite but global relatively to user blocks (I think that it is very bad programming practice).
define MyGlide (speed) (x) (y)
glide (([sqrt] of ((((x position) - (x)) * ((x position) - (x))) + (((y position) - (y)) * ((y position) - (y))))) / (speed)) secs to x: (x) y: (y)
just because I can't create blocks like Square, Length, CalcSpeed, etc. and I do not want to create mess of temporary variables — local for spirite but global relatively to user blocks (I think that it is very bad programming practice).
- Botcho_Otkho
- Scratcher
1000+ posts
custom block with return value
I see now that the circumstances of one's birth are irrelevant. It is what you do with the gift of life that determines who you are. - Mewtwo
- Discussion Forums
- » Suggestions
- » custom block with return value