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

#1 2011-06-05 18:32:45

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

Smalltalk+ Tutorials: Chapter 1

Hello! So since you are visiting this page, I assume that you have been courageous enough to learn the amazing language of SmallTalk. You probably know this language as Squeak.

Well, you can call them either.  wink

Download
So, before we start, you need to figure out what you are going to use to test the code in this tutorials.

Here are your options:
[+] You can download the Squeak program and use it. This is the thing that Scratch was made in.
[+] You can download the source of the Scratch program. I recommend that you use this when making a modification.  wink 
[+] If you haven't already, you can just download the normal scratch.

Browser
Now, even though you have finished downloading, you still need to get to the browser. [+]The Browser is a whole system that holds all the code for the program/morph.

This is where you will do your main coding.
Now of course, since I have listed down multiple programs to use in this tutorial, there are multiple ways to get to the Browser.

• For Squeak: This is really easy, because, all you have to do is right click the gray area. A menu called 'World' should pop-up. Then click the option 'Open...'. Then click 'Browser'.

• For the Source: Click the 'File' menu while clicking Shift. Then click the option 'Exit User Mode'. A gray area surrounds the bottom and right side. Right click the gray area. A menu called 'World' should pop-up. Then click the option 'Open...'. Then click 'Browser'.

[+] • For Scratch: Hold shift and click the 'R' in the Scratch logo (look at picture). Then click the option 'Turn fill screen off'. A gray area surrounds the bottom and right side. Right click the gray area. A menu called 'World' should pop-up. Then click the option 'Open...'. Then click 'Browser'.

Good, now we can start coding!  big_smile

Blockspecs and Methods
Okay, for starters, we need to learn about methods and blockspecs.
Methods are the real core of the code. Its like a file that runs one code.
Blockspecs are just pieces of code that calls the methods. The blockspec for the 'move () steps' block is:

Code:

('move %n steps' #- #forward:)

We will learn more about the actual content later.  smile
But you see? The '#forward:' part calls the method 'forward:':

Code:

forward: distance
    "Move the object forward (i.e., the direction of its heading) by the given distance.
    Avoid infinite or NaN coordinates"

    | radians deltaP newPos newX newY |
    radians _ rotationDegrees degreesToRadians.
    deltaP _ ((radians cos)@(radians sin)) * distance.
    newPos _ self position + deltaP.
    newX _ newPos x.
    newY _ newPos y.
    newX isNaN ifTrue: [newX _ 0].
    newX isInf ifTrue: [newX _ newX sign * 10000].
    newY isNaN ifTrue: [newY _ 0].
    newY isInf ifTrue: [newY _ newY sign * 10000].
    self position: newX @ newY.
    self keepOnScreen.

Of course, I don't expect you to understand you.  wink  Some code I don't even understand fully  tongue


So when you call the 'forward:' method with that little blockspec, it will do all that code!  big_smile
For further demonstration, go to the browser, make sure that the 'class' button is selected, and click Scratch-Objects, and then ScratchSpriteMorph, then block specs, and finally blockSpecs. This is where a lot of the blockspecs for blocks are held. Others are held at 'Scratch-Objects > ScratchStageMorph > block specs > blockSpecs' and  'Scratch-Objects > ScriptableScratchMorph > block specs > blockSpecs'.
To see the methods, click the button 'Instance' and go to the directed area.

This is the end of this chapter. The meaning of this chapter was to get you familiar with the area we will be coding in in later chapters. I hope it was helpful! If you need help, just leave a comment.  big_smile

~ProgrammingFreak

Last edited by ProgrammingFreak (2011-06-06 05:53:33)

Offline

 

#2 2011-06-06 01:11:57

meew0
Scratcher
Registered: 2010-02-22
Posts: 1000+

Re: Smalltalk+ Tutorials: Chapter 1

Lol- the blockspec for the 'say' block is: move %n steps

I think you need to fix that  smile


http://i.imgur.com/mJV3j.pnghttp://i.imgur.com/HwWAX.pnghttp://i.imgur.com/sZ7Ui.pnghttp://i.imgur.com/0y6yh.pnghttp://i.imgur.com/nOC4l.png

Offline

 

#3 2011-06-06 05:55:11

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

Re: Smalltalk+ Tutorials: Chapter 1

meew0 wrote:

Lol- the blockspec for the 'say' block is: move %n steps

I think you need to fix that  smile

Oh thanks  smile  I was going to do that block, but then switched, so yeah.  tongue

Offline

 

#4 2011-06-06 11:26:06

deerel
Scratcher
Registered: 2008-08-23
Posts: 89

Re: Smalltalk+ Tutorials: Chapter 1

Smalltalk is not written with capital T.
Please, do not mock the only true OOP language that is out there by incorrectly spelling its name.
Thanks,
the old Smalltalker

Offline

 

#5 2011-06-06 11:32:26

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Smalltalk+ Tutorials: Chapter 1

deerel wrote:

Smalltalk is not written with capital T.
Please, do not mock the only true OOP language that is out there by incorrectly spelling its name.
Thanks,
the old Smalltalker

Smalltalk-80 has a 80 on the end.
It is NOT mocking. It is a simple spelling incorrection.

Offline

 

#6 2011-06-06 14:09:05

deerel
Scratcher
Registered: 2008-08-23
Posts: 89

Re: Smalltalk+ Tutorials: Chapter 1

Ok, sorry.

Offline

 

#7 2011-06-06 14:13:42

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

Re: Smalltalk+ Tutorials: Chapter 1

deerel wrote:

Ok, sorry.

Me too.  smile  I'll request a change.  wink

Offline

 

Board footer