This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-02-24 00:25:26

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

ITopic: Cool Source code tricks...

This tutorial will give you a basic feel for the MIT squeak editor, and altering Scratch in general. I have tried to include numerous images and such to make it as clear as possible, but feel free to comment with any suggestions.

Let's begin with the blank gray screen of squeak. First left click on that gray, select “open…,” and select “Scratch/Streak”.
This opens a draggable-around Scratch/Streak window.
To resize hold alt and click on the window, and drag the “http://docs.google.com/File?id=dfbw6jtq_5dcbq9sgj_b”pin.
OK, now do the same as above, but this time select “browser” from the “open” list.
This opens the system browser, what most of the programming will go in to:
http://docs.google.com/File?id=dfbw6jtq_6g8wb8ffw_b
The little green circle allows you to resize this window. Just hover over the edge to get it. The X quits the window, the “O” minimizes, and the paper opens the window options. You’ll notice the 4 navigation panes above, and the coding pane below. These let you navigate and change the hierarchy of Scratch/Streak. The “instance|?|class”
Is for the 3 main categories. “Class” generally defines that an object exists, whereas instance defines what it does. ? is for comments, which don’t work. Lets get started. Navigate as follows: 1 Scratch-Objects, 2 ScriptableScratchMorph, 3 Class, 4 Scratch, 5 Blockspecs:
http://docs.google.com/File?id=dfbw6jtq_7g2h7smz6_b
See how I highlighted “(‘if %b’ #c #doIfElse)”? This is the basic syntax for defining the existence of a block. There is:
• opening bracket
• single quote
• The text to be displayed on the block, input areæ represented by %letter, such as %n is a numerical inserter, %b is Boolean. Here's the full list:

Code:

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.

• Single quote
• “#” sign.
• Letter representing the block type, - being a normal command block, b is Boolean, r a reporter, c is a bar.
• “#” sign.
• Message to be corresponded in the instance side.
• This may be followed by Another one or few stand alone numbers, # followed by a number, or value in single quotes. These define the default value of the inserters.
• Closing bracket.
The message can also define special forms, such as the above’s corresponding function tells how to do the else bar.
What we now want to do is go over to “obsoleteBlockSpecs.”
Highlight each section…
http://docs.google.com/File?id=dfbw6jtq_8hgcctqcb_b
And Copy/Paste into the corresponding section of “blockSpecs”: (See that ‘numbers’ before? All following this will show under numbers.
http://docs.google.com/File?id=dfbw6jtq_9gp3qj8qg_b
Now right click “accept”
http://docs.google.com/File?id=dfbw6jtq_10fc4ndbhf_b
Et Voila! You’ve resurrected an “obsolete” block!
Repeat this process for the rest. These blocks will work in normal Scratch/Streak, they’ll just be red.
Now that we have the obsoletes’, lets try some other cheats. Go to:
1 Scratch-Objects, 2 ScratchSpriteMorph, 3 Class, 4 Scratch, 5 Blockspecs:
http://docs.google.com/File?id=dfbw6jtq_11gjcfqxhr_b
See in the single quotes of both where it’s says 'color'?
Change this to, say saturation: http://docs.google.com/File?id=dfbw6jtq_12mfv7z8j9_b
Which, when accepted, gives this: http://docs.google.com/File?id=dfbw6jtq_13dhrqhmfp_b, Which produces this:
http://docs.google.com/File?id=dfbw6jtq_14fhp7krfn_b
Neat,eh? Try setting it to blur, pointillize, or water as well!
One more thing: go back to 1 Scratch-Objects, 2 ScriptableScratchMorph, 3 Class, 4 Scratch, 5 Blockspecs, and find the equals block: http://docs.google.com/File?id=dfbw6jtq_15ftx4x6gx_b. See the
‘#- #-‘? This means that the two inserters will be blank. If, however, you put a string into them (replacing the dash), then they will be forced to hold it. How scratch does this is to “temporarily” make it a square string inserter. (http://docs.google.com/File?id=dfbw6jtq_16ck3hc4hb_b) You could also change the “%n” to a “%s” which is the “code” for a string inserter, but that would render it incompatible with normal Scratch/Streak. Using the above methods you can also make entirely new blocks: http://docs.google.com/File?id=dfbw6jtq_17zfzs5fgb_b
And force stuff into other blocks:
http://docs.google.com/File?id=dfbw6jtq_19g3fbvmhp_b

Another thing you can do is:
Drag a block out to the gray, and Alt+click it.
http://docs.google.com/File?id=dfbw6jtq_207s5gjkgp_b
Click the red menu icon, and select change colour…
Edit as you wish… And use in your Scripts!
http://docs.google.com/File?id=dfbw6jtq_21drvvf8ds_b
http://docs.google.com/File?id=dfbw6jtq_22dmrfrqdp_b
Certain other blocks can only easily be gotten by going to the version of Scratch/Streak it came from. The 1.2beta comment block is an example:
http://docs.google.com/File?id=dfbw6jtq_23crr4pwd4_b
It’ll show up red in everything after 1.1, gray in 1.2beta. It is obsolete before 1.2.

Hope this helps in your endeavor to utilise the scratch source code!
I will make a more advanced collection of information soon, for those who want to continue.

Last edited by billyedward (2011-04-24 22:56:39)


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#2 2010-02-24 01:07:48

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Really nice guide, I'll be using this.

Last edited by hmnwilson (2010-02-24 01:09:00)


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#3 2010-02-24 07:48:22

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Billyedward - Are you interested in helping me with this (http://scratch.mit.edu/forums/viewtopic.php?id=29439 ) ? You're a source code pro after all ^^

Very cool tricks you shared btw  big_smile


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#4 2010-02-24 07:55:36

floatingmagictree
Scratcher
Registered: 2008-10-21
Posts: 1000+

Re: ITopic: Cool Source code tricks...

One question: If you edit the source code and make new blocks like these, can the project with the new blocks be uploaded to the website normally?

Offline

 

#5 2010-02-24 08:03:09

Greenboi
Scratcher
Registered: 2010-01-30
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Wow nice gude! I'll be sure to use it soon.  smile

Offline

 

#6 2010-02-24 17:45:32

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: ITopic: Cool Source code tricks...

floatingmagictree wrote:

One question: If you edit the source code and make new blocks like these, can the project with the new blocks be uploaded to the website normally?

The obsolete ones DO work in normal, unhacked scratch, but not online, as do the special image effects. Unfortunately, though, the blocks that you create from scratch (pun intended) only work in the version that you've made.

So no, none work online  sad .


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#7 2010-02-24 20:55:44

bigreader
Scratcher
Registered: 2007-08-14
Posts: 100+

Re: ITopic: Cool Source code tricks...

Yay! Zombie blocks!!


I'm currently taking a break from Scratch.
Zing - now even easier to install!

Offline

 

#8 2010-02-24 21:10:39

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Awesome!


http://i.imgur.com/WBkM2QQ.png

Offline

 

#9 2010-02-25 04:21:43

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: ITopic: Cool Source code tricks...

That's incredible!  yikes


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#10 2010-02-25 04:26:42

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Wow!  yikes

And it works online and downloaded even if you haven't saved it with the new settings...  yikes


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

#11 2010-02-25 04:50:18

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Omg!!!!!!


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#12 2010-02-26 16:35:17

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Hm... do all the blocks from your screenshot actually work? If so, impressive.


nXIII

Offline

 

#13 2010-02-26 16:51:01

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Wow...very nice guide!


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#14 2010-02-26 17:53:01

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Epic!

Offline

 

#15 2010-02-26 18:03:54

steppenwulf
Scratcher
Registered: 2009-07-23
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Hmm, you're pretty good at source code, billyedward. Thanks for this guide, I'm going to put this to the test today.  big_smile


I'm graduating HS this April and going to college in the Fall.

Offline

 

#16 2010-02-26 23:43:09

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: ITopic: Cool Source code tricks...

nXIII wrote:

Hm... do all the blocks from your screenshot actually work? If so, impressive.

Not all... however this tutorial does not explain how to make them work, just how to get them to show. That is coming in part 2.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#17 2010-02-27 00:47:11

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Hey, you're stickied!  big_smile


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#18 2010-02-27 00:53:17

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: ITopic: Cool Source code tricks...

I was going to say that...  tongue

Hooray! But I'm not planning to make any projects with it... just to be safe for 2.0.  wink


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

#19 2010-02-27 11:15:18

Stickman704
Scratcher
Registered: 2009-01-31
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Cool guide. Is there any way to make an in between () and () block? I've been looking for easy ways to do it but failing.


Dun dun dun dun dun dun.... dun dun dun dun dun dun...  tongue

Offline

 

#20 2010-02-27 18:37:57

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: ITopic: Cool Source code tricks...

Stickman704 wrote:

Cool guide. Is there any way to make an in between () and () block? I've been looking for easy ways to do it but failing.

Yes. Simply test for whether it is less than the lesser number, and greater than the greater one.
This code does what you want:

Code:

number: t1 isBetween: t2 and: t3 
    ^ t1 >= t2 & (t1 <= t3)

"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#21 2010-02-27 19:20:39

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: ITopic: Cool Source code tricks...

billyedward, I have a question: How do you get the blocks you made to work?


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#22 2010-02-27 20:37:10

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Jonathanpb wrote:

billyedward, I have a question: How do you get the blocks you made to work?

Ok, open a system browser, select one of the three scriptable morphs, then select a category to put the function in. Next, delete the text in the bottommost pane and replace it with your method. For example:

openWindow: t1
    | window |
    window _ SystemWindow new.
    window setLabel: t1 asString.
    window openInWorld: World

Press alt + s, and now you can call this method from the blockSpecs

Last edited by nXIII (2010-02-27 20:37:39)


nXIII

Offline

 

#23 2010-02-27 21:25:36

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: ITopic: Cool Source code tricks...

nXIII wrote:

Jonathanpb wrote:

billyedward, I have a question: How do you get the blocks you made to work?

Ok, open a system browser, select one of the three scriptable morphs, then select a category to put the function in. Next, delete the text in the bottommost pane and replace it with your method. For example:

openWindow: t1
    | window |
    window _ SystemWindow new.
    window setLabel: t1 asString.
    window openInWorld: World

Press alt + s, and now you can call this method from the blockSpecs

THANK YOU SO MUCH!!!  big_smile


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#24 2010-02-27 22:44:30

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: ITopic: Cool Source code tricks...

Jonathanpb wrote:

billyedward, I have a question: How do you get the blocks you made to work?

That is a considerably more advanced thing. I made this topic as a guide to get totally new squeakers introduced to the squeak IDE, and the scratch source code.

In a nutshell, you want to make a function that matches the symbol specified in the block spec (the text followed by the #). Create it under scriptableScratchMorph > instance > appropriateOps. However, I will make part 2 or three of this guide series explain this.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#25 2010-02-27 22:54:27

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Hopefully they can get stickied too...  smile


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

Board footer