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

#151 2010-07-22 21:27:46

waveOSBeta
Scratcher
Registered: 2009-12-08
Posts: 1000+

Re: ITopic: Cool Source code tricks...

billyedward wrote:

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 areas 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.

Oh, great master of the source code: Will you teach us the blocks in the image?


http://internetometer.com/image/10202.png]
New signature coming soon!  smile

Offline

 

#152 2010-08-10 11:01:59

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Please.


/* No comment */

Offline

 

#153 2010-08-24 18:55:47

kinker
Scratcher
Registered: 2010-08-01
Posts: 100+

Re: ITopic: Cool Source code tricks...

I want all the blocks spec and the code for each one to work!  lol


Put in the weirdness: http://i54.tinypic.com/zl6fph.pnghttp://img821.imageshack.us/i/gobanim2.gif/kinker style! [url]http://internetometer.com/image/16724.png[/url]♬♫ 92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this into your signature. ♫♪

Offline

 

#154 2010-11-06 19:08:13

kinker
Scratcher
Registered: 2010-08-01
Posts: 100+

Re: ITopic: Cool Source code tricks...

kinker wrote:

I want all the blocks spec and the code for each one to work!  lol

and do it nao or else u will be making a bad mistake.


Put in the weirdness: http://i54.tinypic.com/zl6fph.pnghttp://img821.imageshack.us/i/gobanim2.gif/kinker style! [url]http://internetometer.com/image/16724.png[/url]♬♫ 92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this into your signature. ♫♪

Offline

 

#155 2010-11-06 21:29:44

WindozeNT
Scratcher
Registered: 2010-06-05
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Wow! Is there a way I can get the Scratch ROM Image containing the blocks in the screenshots?


http://i48.tinypic.com/rlyo80.png
Ever since Misc was killed, I've pretty much stopped going to Scratch Forums...

Offline

 

#156 2010-11-06 21:31:16

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: ITopic: Cool Source code tricks...

kinker wrote:

kinker wrote:

I want all the blocks spec and the code for each one to work!  lol

and do it nao or else u will be making a bad mistake.

Dude. Find it out yourself. Learn some coding and please stop trying to make others do things that you can do yourself!


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#157 2011-01-10 14:42:04

-Stendika-
Scratcher
Registered: 2009-11-12
Posts: 74

Re: ITopic: Cool Source code tricks...

Once you've hacked into Scratch, and used the Change Sorter, how do you save the program?


http://i1336.photobucket.com/albums/o660/Stendika/gbanner1_zpsd0178027.png
My latest games can be found here. Please view and give feedback!

Offline

 

#158 2011-01-10 14:45:27

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: ITopic: Cool Source code tricks...

-Stendika- wrote:

Once you've hacked into Scratch, and used the Change Sorter, how do you save the program?

to save the image? are you doing this in normal scratch or the source?

Offline

 

#159 2011-01-10 17:29:08

-Stendika-
Scratcher
Registered: 2009-11-12
Posts: 74

Re: ITopic: Cool Source code tricks...

Basically, how do you save a new version of the source code?


http://i1336.photobucket.com/albums/o660/Stendika/gbanner1_zpsd0178027.png
My latest games can be found here. Please view and give feedback!

Offline

 

#160 2011-01-10 17:31:46

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: ITopic: Cool Source code tricks...

AHEM.

You rename the current one and save it. lol.


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#161 2011-01-10 17:36:41

-Stendika-
Scratcher
Registered: 2009-11-12
Posts: 74

Re: ITopic: Cool Source code tricks...

BUT HOW DO YOU SAVE IT?!?!?

"Save image for end-user" just freezes it up...


http://i1336.photobucket.com/albums/o660/Stendika/gbanner1_zpsd0178027.png
My latest games can be found here. Please view and give feedback!

Offline

 

#162 2011-01-10 18:08:54

-Stendika-
Scratcher
Registered: 2009-11-12
Posts: 74

Re: ITopic: Cool Source code tricks...

Never mind. I got it. I'm working on a simple scratch mod called "shred" right now.


http://i1336.photobucket.com/albums/o660/Stendika/gbanner1_zpsd0178027.png
My latest games can be found here. Please view and give feedback!

Offline

 

#163 2011-01-16 03:24:23

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: ITopic: Cool Source code tricks...

As this is an ITopic, you might want to update this for scratch 1.4.
Also, the %i is the 1/last/any of a list, while %I is the MIDI instruments.
Thanks.

Offline

 

#164 2011-01-19 07:57:28

hpotter134
Scratcher
Registered: 2010-02-21
Posts: 100+

Re: ITopic: Cool Source code tricks...

billyedward wrote:

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.

I have a question: When I use %m in my custom blocks, the dropdown list contains mouse pointer, which isn't a sprite. But in the block ''%a of %m', the dropdown list does NOT contain the mouse pointer, and instead contains the stage. Why is that? Isn't the coding the same?


http://i45.tinypic.com/fxgtvc.png

Offline

 

#165 2011-01-19 09:56:00

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: ITopic: Cool Source code tricks...

well, there seems to be something in Scratch-Blocks -> SpriteArgMorph -> event handling -> fixGetAttribueBlock that makes it come out right. i don't know how its done.
Wait: its in the present menu.

Code:

presentMenu
    | t1 t2 t3 t4 t5 |
    (t1 _ self ownerThatIsA: ScratchFrameMorph) ifNil: [^ self].
    (owner isKindOf: CommandBlockMorph)
        ifTrue: [t2 _ owner selector].
    t3 _ t1 scratchObjects.
    t3 sort: [:t6 :t7 | t6 objName asLowercase < t7 objName asLowercase].
    t4 _ CustomMenu new.
    t2 = #getAttribute:of:
        ifTrue: [t4 add: 'Stage' localized asUTF8 action: t1 workPane]
        ifFalse: 
            [t4 add: 'mouse-pointer' localized asUTF8 action: #mouse.
            t2 = #touching: ifTrue: [t4 add: 'edge' localized asUTF8 action: #edge].
            t3 _ t3 copyWithout: owner receiver].
    t3 size > 0 ifTrue: [t4 addLine].
    t3 do: [:t8 | t4 add: t8 objName action: t8].
    (t5 _ t4 startUp) ifNil: [^ self].
    morph _ t5.
    self fixGetAttribueBlock.
    self updateLabel

i don't understand it all, but if its the get attribute block, it adds stage, else, it adds mouse. if its the touching block, it also adds edge.
If you give the block and method, i'll give you the new code to replace that with.

Last edited by scimonster (2011-01-19 09:57:17)

Offline

 

#166 2011-01-19 14:49:44

hpotter134
Scratcher
Registered: 2010-02-21
Posts: 100+

Re: ITopic: Cool Source code tricks...

Well, in fact, the block I was making at that time was 'make %m go to x: %n y: %n'

http://img826.imageshack.us/img826/9631/makemmovensteps.gif

This, and the 'make %m move %n steps' block. You can't 'move' the mouse-pointer, can you? Nor can you move the Stage. So in this case, %m should just be a drop down list of all the sprites, NOT including the Stage, or the mouse pointer.

I think what happened in the coding of presentMenu, is the developers intended to make each sprite control itself, and all the blocks containing %m were used only to get the info, not to modify it. So the list was intended for blocks such as 'go to %m', and you COULD go to the mouse pointer, but you CANNOT move the mouse pointer.

Am I making sense or am I rambling?


http://i45.tinypic.com/fxgtvc.png

Offline

 

#167 2011-01-19 15:05:24

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: ITopic: Cool Source code tricks...

you make sense, but i have to get offline now.
i'll do tommorow.

Offline

 

#168 2011-01-19 16:07:25

Necromaster
Scratcher
Registered: 2010-04-07
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Cool!  smile  I'm experimenting with new blocks now...

Offline

 

#169 2011-01-19 16:11:44

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Necromaster wrote:

Cool!  smile  I'm experimenting with new blocks now...

cool! Do you know squeak? I have learned it a lot better! Good Luck!

Offline

 

#170 2011-01-20 01:35:03

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: ITopic: Cool Source code tricks...

hpotter134 wrote:

Well, in fact, the block I was making at that time was 'make %m go to x: %n y: %n'

http://img826.imageshack.us/img826/9631/makemmovensteps.gif

This, and the 'make %m move %n steps' block. You can't 'move' the mouse-pointer, can you? Nor can you move the Stage. So in this case, %m should just be a drop down list of all the sprites, NOT including the Stage, or the mouse pointer.

I think what happened in the coding of presentMenu, is the developers intended to make each sprite control itself, and all the blocks containing %m were used only to get the info, not to modify it. So the list was intended for blocks such as 'go to %m', and you COULD go to the mouse pointer, but you CANNOT move the mouse pointer.

Am I making sense or am I rambling?

ok, put the code in Scratch-Blocks -> SpriteArgMorph (instance) -> event handling -> presentMenu.

Code:

presentMenu
    | t1 t2 t3 t4 t5 |
    (t1 _ self ownerThatIsA: ScratchFrameMorph) ifNil: [^ self].
    (owner isKindOf: CommandBlockMorph)
        ifTrue: [t2 _ owner selector].
    t3 _ t1 scratchObjects.
    t3 sort: [:t6 :t7 | t6 objName asLowercase < t7 objName asLowercase].
    t4 _ CustomMenu new.
    t2 = #getAttribute:of:
        ifTrue: [t4 add: 'Stage' localized asUTF8 action: t1 workPane]
        ifFalse: t2 = #make:gotoX:y:
        ifFalse: 
            [t4 add: 'mouse-pointer' localized asUTF8 action: #mouse.
            t2 = #touching: ifTrue: [t4 add: 'edge' localized asUTF8 action: #edge].
            t3 _ t3 copyWithout: owner receiver].
    t3 size > 0 ifTrue: [t4 addLine].
    t3 do: [:t8 | t4 add: t8 objName action: t8].
    (t5 _ t4 startUp) ifNil: [^ self].
    morph _ t5.
    self fixGetAttribueBlock.
    self updateLabel

it also fixes for the sprite touching sprite block, if you have it.
if the method you are using is not what you shared to the library, change

Code:

        ifFalse: t2 = #make:gotoX:y:

to whatever your method is.

Offline

 

#171 2011-01-20 18:04:04

hpotter134
Scratcher
Registered: 2010-02-21
Posts: 100+

Re: ITopic: Cool Source code tricks...

Thanks for taking a look at it! I tried what you suggested, but it complains about the ifTrue:ifFalse:ifFalse:.

http://img838.imageshack.us/img838/3768/messagenotunderstoodift.png

Is that valid Smalltalk? I don't think you can put two ifFalses in a row, can you?


http://i45.tinypic.com/fxgtvc.png

Offline

 

#172 2011-01-21 02:43:03

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: ITopic: Cool Source code tricks...

maybe put a peroid after the first.

Offline

 

#173 2011-01-21 08:02:20

hpotter134
Scratcher
Registered: 2010-02-21
Posts: 100+

Re: ITopic: Cool Source code tricks...

After a bit of trial and error, this worked best:

Code:

 presentMenu
    | t1 t2 t3 t4 t5 |
    (t1 _ self ownerThatIsA: ScratchFrameMorph) ifNil: [^ self].
    (owner isKindOf: CommandBlockMorph)
        ifTrue: [t2 _ owner selector].
    t3 _ t1 scratchObjects.
    t3 sort: [:t6 :t7 | t6 objName asLowercase < t7 objName asLowercase].
    t4 _ CustomMenu new.
    t2 = #getAttribute:of:
        ifTrue: [t4 add: 'Stage' localized asUTF8 action: t1 workPane]
        ifFalse: [t2 = #make:gotoX:y:
                ifFalse: 
                    [t4 add: 'mouse-pointer' localized asUTF8 action: #mouse.
                    t2 = #touching: ifTrue: [t4 add: 'edge' localized asUTF8 action: #edge].
                    t3 _ t3 copyWithout: owner receiver]].
    t3 size > 0 ifTrue: [t4 addLine].
    t3 do: [:t8 | t4 add: t8 objName action: t8].
    (t5 _ t4 startUp) ifNil: [^ self].
    morph _ t5.
    self fixGetAttribueBlock.
    self updateLabel

This returned the proper drop-down lists!

http://img831.imageshack.us/img831/2629/dropdownlist4makegotoxy.png
http://img210.imageshack.us/img210/482/dropdownlist4goto.png
http://img88.imageshack.us/img88/931/dropdownlist4aofm.png
Thanks scimonster!

Last edited by hpotter134 (2011-01-21 08:16:49)


http://i45.tinypic.com/fxgtvc.png

Offline

 

#174 2011-01-22 13:30:37

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: ITopic: Cool Source code tricks...

Your welcome.
Glad to help where I can!

Offline

 

#175 2011-02-05 17:34:33

Zolk
New Scratcher
Registered: 2011-02-05
Posts: 4

Re: ITopic: Cool Source code tricks...

what's the blank gray screen of squeak?

Offline

 

Board footer