Note. IF THIS IS THE FIRST TIME YOU ARE READING THIS THREAD, READ THIS!
I am not doing any requests for blocks. This thread is now defunct, so please use it for information only and do not post requests. I will not answer any requests nor anymore clarifications. There's an amazing block library now where you can find many more blocks. If you have a good question about mods, you may post, but your question might not be answered.
Hey Scratchers!
Are you all wondering how to make your own blocks in Scratch using Squeak? Well then, you've come to the right place. This forum thread will include tutorials, links to other projects, and more!
The blocks are pretty much self-explanatory, so no need for a list of what they do. i'll start with the block-making right away.
Note for the lazy people: this tutorial aims to teach people to work in Squeak, not only to get the new blocks. So do not ask for my image file.
First, we have to open the system browser. Here's a tutorial for it:
T - Open Browser
Now, we're ready to start programming. From the browser, go to:
>Scratch-Objects
>ScriptableScratchMorph
>Click onto Class
>Scratch (or) BlockSpecs
>blockSpecks
Here we've got the main bit of blocks. it all looks very messy, so you can use the find option if you want to save your eyes when looking for a block. Now let's take a block to analyse: the yellow repeat(X) block.
('repeat %n' c doRepeat)
That's the specification for that block.
The block coding structure is as follows:
('repeat %n' #c #doRepeat 10)
the block is identified by the two brackets (blue).
the block text is in between apostrophes (black).
the block type identifier or block arguments follow a # sign (red).
the command also follows a # sign (green).
any additional arguments follow the command (purple).
the %n in the block is the input box, where the user can put the number. in fact, %n produces that round textbox where only numbers can be inserted. here's the full list:
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 all of a list.
Credit to billyedward for this list.
the repeat block, having to 'host' other blocks in it, is C shaped. that's why the block argument (above in red) is a c.
Here's a brief list of the different arguments:
#- 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)
but it's not all that simple! now that we've got the block in the block palette, we need to give it the code it needs to perform the action. for this you need to go to 'instance', then to the appropriate 'ops'. there, after creating a method, you can add the code you need.
________
Now that you know a bit about the structure, we can move on quickly to the actual new blocks you saw at the beginning. I'm not going to add them into this post, it would be too long. you'll find the different blocks in different posts.
I hope you'll enjoy your new blocks!
Last edited by LS97 (2012-12-18 11:27:40)
Offline
The 'Get time/date' block
<get [date]> <get [time]> <get [hours]>Here we go!
('get %s' #r #getTime: 'date')
Then go to the instance section, then to 'other ops' and replace the code of broadcast: with the following
getTime: t1 t1 = 'date' ifTrue: [^ Date today]. t1 = 'short date' ifTrue: [^ Date today printFormat: #(1 2 3 $- 2 2 )]. t1 = 'time' ifTrue: [^ Time now]. t1 = 'seconds' ifTrue: [^ Time now seconds]. t1 = 'minutes' ifTrue: [^ Time now minutes]. t1 = 'hours' ifTrue: [^ Time now hours]. t1 = 'day' ifTrue: [^ Date today weekday]. t1 = 'help' ifTrue: [^ 'type date, short date, time, seconds, minutes, day, hours']. ^ 'Error!'
then right-click and click accept. type your initials and you're ready to use the new block!
NOTE:
There's a second, more advanced version of the block, with a drop-down menu instead of a string inserter, but it involves extra coding. If you are willing to take the challenge, please refer to this post. Thanks!
Last edited by LS97 (2012-12-19 06:02:34)
Offline
Nice tutorial!!!
Offline
dav09 wrote:
Nice tutorial!!!
Thanks! if you have any suggestions for some blocks, ask and i might be able to add them in this tutorial.
Offline
The 'showing?' block
This is an easy one. It gives a boolean response (True/False) of whether the sprite is showing or not.
Like before, copy this code into the 'looks' section of blockSpecs in ScratchSpriteMorph
('showing?' #b #getHidden)
then go to instance, 'looks ops' and replace the code in 'hide' with the code below (by the way, you're not deleting the hide block).
getHidden self isHidden = false ifTrue: [^ true]. ^ false
Then right-click, clik accept and (maybe) type your initials. et voilà, you have your 'showing?' block up and ready.
Offline
SeptimusHeap wrote:
What does save stage area do? Does it take a pic of the stage?
yes, it does. it's really easy to make too. if you come back in 5 mins you'll find it up.
Offline
OK. May we use it for our mod, Panther (I guess you've heard of it?)
Offline
The 'save stagearea to sprite' block
save stage area to spriteI did this one on request of SeptimusHeap. it's maybe the easiest of the blocks. No coding needed, just add the block to the blockSpecs in ScratchSpriteMorph:
('save stage area to sprite' #- #grabFromScreen)
that's it! easy right?
PS. in case you didnt know, you have click accept.
Last edited by LS97 (2012-12-19 06:03:24)
Offline
SeptimusHeap wrote:
OK. May we use it for our mod, Panther (I guess you've heard of it?)
Well, i haven't heard of it to be honest, but the link in your sig helped. a lot. of course you may use it, as long as it's got the coding for it already in it (which scratch 1.3 and 1.4 does). i don't mean the coding i put up onthe forums but the one i refer to in the code. in other words, the 'grabFromScreen'.
anyway yes you may.
Offline
The mouse down block
<[left] mouse down?>Another request of SeptimusHeap.
('%s mouse down?' #b #mousePressed: 'left')
then into the instance, into ScriptableScratchMorph, and into 'sensing ops'.
replace the 'mousePressed' code with the one below.
mousePressed: t1 t1 = 'left' ifTrue: [^ Sensor redButtonPressed]. t1 = 'right' ifTrue: [^ Sensor yellowButtonPressed]. t1 = 'middle' ifTrue: [^ Sensor blueButtonPressed]. t1 = 'any' ifTrue: [^ Sensor anyButtonPressed]. t1 = 'left ' ifTrue: [^ Sensor redButtonPressed]. t1 = 'right ' ifTrue: [^ Sensor yellowButtonPressed]. t1 = 'middle ' ifTrue: [^ Sensor blueButtonPressed]. t1 = 'any ' ifTrue: [^ Sensor anyButtonPressed]. ^ Sensor redButtonPressed
Then click accept and it should be fine. you'll find the new block in the sensing category. you can put left, right, middle or any into the box and it'll give you the respective sensor button boolean.
Last edited by LS97 (2012-12-19 06:04:56)
Offline
SeptimusHeap wrote:
You are now an official Panther contributer!
wow, thanks for the honor! could you add me to the list on your site?
Last edited by LS97 (2010-04-18 08:56:38)
Offline
Nice
Offline
LS97 wrote:
The 'Get time/date' block
http://www.freeimagehosting.net/uploads/209a5b329a.gif
Here we go!
The get time/date block reports the time, date, hour, etc. without the user having to insert it manually.
Copy this line of code into a space between two blocks in the 'control' section of blockSpecs in ScriptableScratchMorph.Code:
('get %s' #r #getTime: 'date')Then go to the instance section, then to 'other ops' and replace the code of broadcast: with the following
Code:
getTime: t1 t1 = 'date' ifTrue: [^ Date today]. t1 = 'short date' ifTrue: [^ Date today printFormat: #(1 2 3 $- 2 2 )]. t1 = 'time' ifTrue: [^ Time now]. t1 = 'seconds' ifTrue: [^ Time now seconds]. t1 = 'minutes' ifTrue: [^ Time now minutes]. t1 = 'hours' ifTrue: [^ Time now hours]. t1 = 'day' ifTrue: [^ Date today weekday]. t1 = 'help' ifTrue: [^ 'type date, short date, time, seconds, minutes, day, hours']. ^ 'Error!'then right-click and click accept. type your initials and you're ready to use the new block!
Thats a brillant idea!
Offline
Keba wrote:
Hi there,
Is there a way to create using new blocks using BYOB? I cannot exit fullscreen in BYOB because there is no 'r' in the title bar...
the source code version of BYOB will be coming out sometime in august, these types of custom blocks aren't possible in BYOB. If you use Scratch or the sourcecode for Scratch then you can make custom blocks like these.
Offline
Hm, so there is now way of combining own blocks (eg a "clone block hack") and BYOB togehter? Both hack into the image files, don`t they? So way cant I edit the BYOB`s image file and put some nice blocks into it?
And why is there no source code release of BYOB yet? That sucks, too.
Offline
Keba wrote:
Hm, so there is now way of combining own blocks (eg a "clone block hack") and BYOB togehter? Both hack into the image files, don`t they? So way cant I edit the BYOB`s image file and put some nice blocks into it?
And why is there no source code release of BYOB yet? That sucks, too.
Go ask Jens if there is a way of editing the imagefile, but he said that he removed the Editor from BYOB, I geuss so people couldn't steal the BYOB interface
Offline
Great! I like it! One suggestion for your mousePressed block. I would suggest
^ false
instead of
^ Sensor redButtonPressed
If it even got as far as the last part, it should return false since it doesn't know what your talking about, why test some stuff that is jargon?
Last edited by Sperry (2010-04-18 10:02:12)
Offline
I have another problem. How do I 'save' the changes?
Offline
Aidan wrote:
I have another problem. How do I 'save' the changes?
that's something i didnt include in my tutorial, thanks for reminding me!
Shift-click the R again, and click 'save image for end-user'. then click yes.
Offline
Sperry wrote:
Great! I like it! One suggestion for your mousePressed block. I would suggest
^ false
instead of
^ Sensor redButtonPressed
If it even got as far as the last part, it should return false since it doesn't know what your talking about, why test some stuff that is jargon?
I understand what you mean, but i thought of the lazy people who don't want to enter anything and have it like the default block straight away. what use would it be anyway if it returns false each time?
Offline