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

#1 2012-05-12 15:03:57

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Squeak Tips

Hey guys!
I'm here to teach you a few things about Squeak.
Creating new menus
So, in this tutorial, we will be making one called "Dev" (short for developer, meant to access developer mode)
First, either shift-click-r or shift-click-file (scratch or source) then click in the grey space at the bottom.
Then, click "open..." and then "browser".
Then, go to Scratch-UI-Panes>ScratchFrameMorph>menu/button actions
And then, you will create your very own developer menu by simply copying and pasting:(Must press alt+v in the Squeak editor to paste)

Code:

developerMenu: t1 
    | t2 |
    t2 _ CustomMenu new.
    t2 add: 'turn fill screen on' action: #fillScreenOn.
    t2 add: 'turn fill screen off' action: #fillScreenOff.
    t2 addLine.
    t2 add: 'toggle error catching' action: #toggleErrorCatcher.
    t2 addLine.
    t2 add: 'save image for end user' action: #saveImageForEndUser.
    t2 localize.
    #(1 2 3 ) do: [:t3 | t2 labels at: t3 put: ((t2 labels at: t3)
                copyFrom: 1 to: (t2 labels at: t3) size - 1)
                , ScratchTranslator ellipsesSuffix].
    t2 invokeOn: self at: t1 bottomLeft + (0 @ 10)

Then go to Scratch-UI-Panes>ScratchFrameMorph>initialization>createMenuPanel.
It should look like:

Code:

createMenuPanel
    | t1 t2 |
    menuPanel _ AlignmentMorph new color: Color transparent;
             centering: #center;
             inset: 0;
             height: 0.
    self addShortcutButtonsTo: menuPanel.
    t1 _ #((#File #fileMenu:) (#Edit #editMenu:) (#Help #helpMenu:) ).
    t1 do: 
        [:t3 | 
        t2 _ ScratchMenuTitleMorph new contents: (t3 at: 1) localized;
                 target: self selector: (t3 at: 2).
        menuPanel addMorphBack: t2.
        #helpMenu: = (t3 at: 2) ifFalse: [menuPanel addMorphBack: (Morph new color: Color transparent;
                 extent: 12 @ 5)]].
    topPane addMorph: menuPanel

Now, in between "(#Edit #editMenu:)" and "(#Help #helpMenu:)" insert:

Code:

(#Dev #developerMenu:)

Then right click and click accept, save image for end user, and open your mod or the version of Scratch you just edited.
Creating new drop-downs
So, in this tutorial, we will be replacing the hide and show blocks with a drop-down.
First, either shift-click-r or shift-click-file (scratch or source) then click in the grey space at the bottom.
Next, click "open..." and then "browser".
Now, go to Scratch-Objects>ScratchSpriteMorph>looks ops.
Now to insert the list of options:

Code:

hideShowOptions
    ^ #('hide' 'show')

We will use that later, for now, let's move on to the action.

Code:

hideShow: t1 
    | t2 |
    t1 = 'show' ifTrue: [t2 _ true].
    t1 = 'hide' ifTrue: [t2 _ false].
    self isHidden: t2

That is the action that will be used in the block spec.
Now let's define the drop-down. Go to: Scratch-Blocks>CommandBlockMorph>-- all -->uncoloredArgMorphFor:
It should look something like (slightly edited to my pleasure)

Code:

uncoloredArgMorphFor: t1 
    | t2 |
    t2 _ t1 at: 2.
    $a = t2 ifTrue: [^ AttributeArgMorph new choice: 'volume'].
    $A = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #arithmeticFunctions].
    $b = t2 ifTrue: [^ BooleanArgMorph new].
    $B = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #hideShowOptions].
    $c = t2 ifTrue: [^ ColorArgMorph new showPalette: true].
    $C = t2 ifTrue: [^ ColorArgMorph new showPalette: false].
    $d = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '0';
         menuSelector: #directionMenu].
    $D = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '48';
         menuSelector: #midiDrumMenu].
    $e = t2 ifTrue: [^ EventTitleMorph new].
    $E = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #mixingNames].
    $f = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #mathFunctionNames;
         choice: 'sqrt'].
    $g = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #graphicEffectNames;
         choice: 'color'].
    $H = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #hookupSensorNames].
    $h = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #hookupBooleanSensorNames].
    $I = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '1';
         menuSelector: #midiInstrumentMenu].
    $i = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '1';
         menuSelector: #listIndexMenu].
    $k = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #keyNames;
         choice: 'space'].
    $L = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #listVarMenu].
    $l = t2 ifTrue: [^ ChoiceOrExpressionArgMorph new getOptionsSelector: #costumeNames;
         choice: 'costume1'].
    $m = t2 ifTrue: [^ SpriteArgMorph new].
    $M = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #motorNames].
    $n = t2 ifTrue: [^ ExpressionArgMorph new numExpression: '10'].
    $N = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '60';
         menuSelector: #noteSelector].
    $o = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #trueFalse].
    $r = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #directionSteps].
    $s = t2 ifTrue: [^ ExpressionArgMorph new stringExpression: ''].
    $S = t2 ifTrue: [^ ChoiceOrExpressionArgMorph new getOptionsSelector: #soundNames;
         choice: 'pop'].
    $v = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #varNamesMenu;
         choice: ''].
    $W = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #motorDirection].
    $x = t2 ifTrue: [^ ChoiceOrExpressionArgMorph new getOptionsSelector: #sceneNames;
         choice: ''].
    $y = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '1';
         menuSelector: #listIndexForDeleteMenu].
    ^ ExpressionArgMorph new numExpression: '10'

Copy&paste:

Code:

    $z = t2 ifTrue: [^ ChoiceOrExpressionArgMorph new getOptionsSelector: #hideShowOptions].

after the y ($y = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '1'; menuSelector: #listIndexForDeleteMenu].)
Now right-click and press accept.
Now go to (make sure you are under class, not instance): Scratch-Objects>ScratchSpriteMorph>block specs>blockSpecs
Look for the looks section and copy&paste:

Code:

('%z self' #- #hideShow: 'show')

and now you have a hide/show drop-down!

Last edited by chanmanpartyman (2012-05-30 12:53:10)

Offline

 

#2 2012-05-12 15:24:58

stickdude123
Scratcher
Registered: 2010-05-31
Posts: 100+

Re: Squeak Tips

thats very helpfull thx  big_smile


http://internetometer.com/imagesmall/34259.png http://www.mediafire.com/convkey/418e/lkb7wmv2n2k73rz5g.jpg         http://blocks.scratchr.org/API.php?user=stickdude123&action=onlineStatus&type=square

Offline

 

#3 2012-05-12 16:06:54

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: Squeak Tips

Welcome  smile

Offline

 

#4 2012-05-12 16:43:44

funelephant
Scratcher
Registered: 2010-07-02
Posts: 1000+

Re: Squeak Tips

Thanks! Can you make one on how to add a button like "Make a List" if you know how to?


nicki begs to differ
http://24.media.tumblr.com/ab0e6e8fd347c5e39c2821bcab9d16e6/tumblr_mgu35sui1L1rfb7aqo2_500.gif

Offline

 

#5 2012-05-12 16:58:41

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: Squeak Tips

Scratch-UI-Support>ResizableToggleButton2>-- all -->helpScreenName is where it's located.

Last edited by chanmanpartyman (2012-05-12 17:32:01)

Offline

 

Board footer