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.
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.
[+] 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!
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:
('move %n steps' #- #forward:)We will learn more about the actual content later.
But you see? The '#forward:' part calls the method 'forward:':
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.
Some code I don't even understand fully
So when you call the 'forward:' method with that little blockspec, it will do all that code!
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.
~ProgrammingFreak
Last edited by ProgrammingFreak (2011-06-06 05:53:33)
Offline
meew0 wrote:
Lol- the blockspec for the 'say' block is: move %n steps
I think you need to fix that![]()
Oh thanks
I was going to do that block, but then switched, so yeah.
Offline
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
deerel wrote:
Ok, sorry.
Me too.
I'll request a change.
Offline