TOCM wrote:
I posted this elsewhere but I think this is the place to do it.
My idea is that you could make a function just like youd make a sprite like this below:
http://img143.imageshack.us/img143/119/ … itexz2.jpg
A function wouldn't have a number of inputs (like variables) and one variable called output, that you have to set at the end of the script, functions would have no costumes or sounds just sripts like this one here that has just 1 input, this function is for squaring a number (ie a number times by itself)
http://img529.imageshack.us/img529/8338/squarezl4.jpg
When you make a Function you also get allong with it a new block in the http://scratch.mit.edu/forums/img/sbcats/numbers.png section like this:
http://img143.imageshack.us/img143/6901 … ocket0.gif
and the block has the same nuber of inputs as the Function, from the code this is what would happen if you used the square block:
http://img143.imageshack.us/img143/370/ … kexeh2.gif
And here's anothe possible one, this one has 2 inputs and works out the size of the difference between 2 numbers (ie there's no minuses involved):
http://img529.imageshack.us/img529/3364/absdiffho8.jpg
With this Function of course you also get this block:
http://img204.imageshack.us/img204/7409 … ockqe8.gif
What you could also do is make a function that uses other functions that you've already made like this one for calculating pytagorases theorum for calculating the length hypotinuse of a right angled triangle from the length of the other 2 sides.
So the inputs here are the lengths of the two other sides of the triangle:
http://img529.imageshack.us/img529/9951 … odecs1.gif
and making this function creates this block:
http://img143.imageshack.us/img143/8139 … ockll3.gif
I have an example of how I currently attempt to tackle functions "my stuff"
That's a great idea!
Offline
Mick wrote:
I think a yellow bock would look good. Maybe the block section cud be called 'Miscellaneous'. http://legoless.wordpress.com/files/2007/07/yello.gif
Okay, I like that, but I can barley read the word.
Offline
you should have a option when you start scratch and when you click new were you can decide whether you want make an new project or if you want to go to my block editor were you build a block and when you save it it goes to a tab named my blocks.
Offline
Another way to factor procedures that might be conceptually simpler, and a better fit to Scratch, would be to add means to send a message to a particular entity. At present, you can broadcast an event and it goes to any receiver that is listening for it. If instead you could say "send X to Y" where X is some data and Y is a sprite, the stage, or the sender of a prior message, then sprites or the stage could have message handlers that respond to specific messages.
In this case a message ought to contain more data than an event - perhaps a simple variable and enough information that a block could REPLY to the message with another message.
So to implement procedures, you would add as few as two blocks: one to send a message to a target, and another to reply to a message.
I would argue that this achieves the objective of encapsulating code in a simple way that fits well with Scratch.
Comments?
Offline
I agree with your suggestion, jwsadler. In order to receive the return value, however, the block which sends the message would have to be a reporter block instead of a command block. I have already made a little prototype for this (a call-response pair of yellow control-blocks, where the "call" reporter lets you select either a specific target or "all"), and it works fine while being easy to understand. I'm also considering posting an experimental version of this in the next Chirp/BYOB release, to gather more experience and feedback from others in the community.
Offline
how do you get to the block maker it is driving me CRAZY
Offline
Jens - I'd love to try it out whenever it's available.
Regards
Jens wrote:
I agree with your suggestion, jwsadler. In order to receive the return value, however, the block which sends the message would have to be a reporter block instead of a command block. I have already made a little prototype for this (a call-response pair of yellow control-blocks, where the "call" reporter lets you select either a specific target or "all"), and it works fine while being easy to understand. I'm also considering posting an experimental version of this in the next Chirp/BYOB release, to gather more experience and feedback from others in the community.
Offline
Jens wrote:
I agree with your suggestion, jwsadler. In order to receive the return value, however, the block which sends the message would have to be a reporter block instead of a command block. I have already made a little prototype for this (a call-response pair of yellow control-blocks, where the "call" reporter lets you select either a specific target or "all"), and it works fine while being easy to understand.
Hi jwsadler, hallo Jens,
Great idea! I've been thinking about such an approach as well for quite some time. Another choiced for the target should be 'self', since this allows subroutines, which is something I need quite often when teaching programming to 7th-graders following the curricula.
What do you think about having three types of callers:
* send [x] to [self|all|target]
* send [x] to [self|all|target] and wait
* send [x] to [self|all|target] and wait for return value
I understand, it would be nice to have a receiver for return-values as well, but I'm not sure whether this is really necessary. A simpler approach might be to use (global or sprite-specific) variables to store return-values. This should be good enough at least for the little projects, my students create usually. It's a nice-to-have though and necessary for real encapsulation. Wouldn' it be enough to have a
* my last return value
block for each sprite? Then you could do things like
* send [x] to [self|all|target] and wait for return value
* some variable := my last return value
Or is there to much chance of getting into race-conditions?
Offline
One ( other ) consideration might be:
If you were allowed to make new blocks...
Would they be merely a compilation of commands & functions featured on other blocks...
Or would the user/programmer be allowed to access a greater library of elemental functions...???
( that could ( hopefully ) be used with the same or nearly the same ease as Scratch itself... ! )
Offline
Jens wrote:
... I have already made a little prototype for this (a call-response pair of yellow control-blocks, where the "call" reporter lets you select either a specific target or "all"), and it works fine while being easy to understand. I'm also considering posting an experimental version of this in the next Chirp/BYOB release, to gather more experience and feedback from others in the community.
I would *love* to use this, whenever you feel ready to share. Is the Scratch team considering including this in 1.4?
- Sophie
Offline
Thanks, Sophie. Procedures/building your own blocks is still experimental, and there are many design issues to be considered, so these won't be included in the official Scratch 1.4 release. But I plan to share another experimental version which will combine these features in a more Scratch-compatible way, when the new Scratch Source Code comes out (I'll also share the source code, so you Smalltalkers can tinker with it)
Offline
Oh, such debates.
Here's my plan for Streak:
I will implement a [run [] internally] command.
This will call internal functions using the squeak syntax.
Ie. [run [pointToX: 34 y: 30] internally] would call the vector subfunction used by the point to spritte[] block.
Then, these internal functions could be added using some menu on the toolbar.
I could make different bits of code, which can be added as needed.
And those who are more technologically astute can make their own.
This would allow for the more advanced users to begin doing more advanced things, yet it would stay nicely out of the way of novices.
It does, however, move away from the 'pure GUI' aspect of scratch, but that isn't too much of a problem, due to the above.
Please reply as to your thoughts!
Offline
For making your own block without having to program and do all sorts of stuff, create a script with a [ When I receive { v} ] block at the top. Make the stack do whatever you want your new block to do, then simply put a [ Broadcast { v} ] wherever you need your new block. Please note that these blocks are project-specific and work only for the sprite the code is in.
Offline
Mick wrote:
I think a yellow bock would look good. It wud be cool if there could be an 'upload block' button. There could be a thing at the top of the screen (e.g. projects, galleries, forums)
called blocks. You could download them onto scratch. Which would be a better place to keep the blocks? In a file or folder, like sounds and costumes or in a block section, like motion or pen? I think the block section is a bad idea cuz it wud get really big after a while. Maybe there could be a block section & your able to import blocks from a file or folder. Maybe the block section cud be called 'Miscellaneous'. http://legoless.wordpress.com/files/2007/07/yello.gif
That's a great idea!
Offline
I think that scratch should be able to work on linux. That would be very useful. (for the people that hate windows.) And having a save block for those that have longer games. Plus an in-game high score board. Thats all i have to say....
Offline
natalie wrote:
As we are looking over all the suggestions, one that is high on the list is giving the ability to define your own blocks in Scratch.
An earlier version of Scratch had the ability to create procedures, but they got confused with broadcast/when-I-receive, so were removed. The hope is that by conceptualizing them as making a new block, the difference will be more concrete.
Kevin Karplus put forward a proposal for how they could work in a previous thread. I want to highlight it here, and invite additional thoughts and suggestions.
Try BYOB by Jens.
it lets you make blocks and procedures. I have it and its awesome!!!
Offline
<when I receive[ <when I receive[ <forever><when[ ]clicked><when green flag clicked><play sound[ <play sound[ ]and waits><think[ ]for( )secs><change[ ]effect by( <clear graphic effects><set size to( )%><when green flag clicked>
<forever>
<wait(1 )secs>
<play sound[ recording1
Offline
you nlofb [inappropriate comment with inappropriate language removed by moderator. Please read the Terms of Use.)
Last edited by cheddargirl (2009-11-14 01:18:33)
Offline