The tutorial on the Scratch Wiki is confusing. Can someone post a kid friendly tutorial?
Offline
I am writing a tutorial book on how to make a Scratch Mod. It's not even close to done yet, and it isn't edited, but I could post some of it. Do you want me to do that?
Offline
scratcher7_13 wrote:
I am writing a tutorial book on how to make a Scratch Mod. It's not even close to done yet, and it isn't edited, but I could post some of it. Do you want me to do that?
Sure. I just remembered about another forum post with Squeak.
Offline
scratcher7_13 wrote:
Chapter 2: Block Specs and Simple Coding
This chapter will focus on how block specs work and teach some simple things about coding in Squeak! You have seen some block specs, so this section should not be too hard. This next section will explain the different parts of a block spec. We will use this block spec as an example: (‘join %s %s’ #r #concatenate:with: ‘hello’ ‘world’). This is the block spec for an existing block, the Join reporter block. The ‘join %s %s’ part is what is shown on the block. The %s is a string inserter. It makes a square on the block that allows text to be typed in to it. There are many other inputs, such as a color inserter and a numerical inserter. These will be discussed soon, but not right now. The #r is the block type. These are the different block types:
#- This is the normal code block.
#b This is a Boolean reporter block.
#r This is a normal reporter block.
#c This is a C block (an iterator.)
#t This is a timed block (like the wait () seconds block.)
#s This is a special form block.
#S This is the When Flag Clicked hat block.
#K This is the When [_] Key Pressed hat block.
#M This is the When Sprite [_] Clicked hat block.
#W This is the When <> Is true hat block.
The last block is obsolete, but it will be added to Sizzle soon. The last part of the block spec, the #concatenate:with: ‘hello’ ‘world’ is the block command. This tells the block to find the ‘concatenate: t1 with: t2’ command and execute the code. The ‘hello’ ‘world’ tells the block what to put into the string inserter as the default strings. There are many different types of inserters (as I said before,) so I won’t list them all here, but the most common ones are:
%s A string inserter.
%n A numerical inserter. (this only excepts numbers.)
%C A color inserter (no palette showing.)
%b A Boolean reporter inserter.
%m A list of sprites.
Soon there will be another inserter and two types of blocks added. I won’t go into much detail about this yet, but we’ll get to it. Next are some simple coding things. First, each code has a heading, and this is how the program finds each section of code. A lot of code in Squeak is referencing other code. Sometimes it’s hard to tell which code are Squeak commands and which are referencing other code. Here are some basics that are good to know for programming blocks.
^ This is the caret symbol. It reports whatever is after it. This is used in all reporter blocks.
* This is the multiplicaion symbol.
+This is the addition symbol.
-This is the subtraction symbol.
/This is the division symbol.
raisedTo: This indicates exponentiation.
|var| This is how variables are declared. It is conventional to use t1, t2, etc. as variable names.
abs: This is the absolute value function.
sqrt: This is the square root function.
=,>,< These compare two expressions.
true This reports true.
false This reports false.
The next block that will be made is the exponentiation reporter. Go to block specs (you know the drill.) Find the reporter section and type this block spec: (‘%n ^ %n’ #r #n:toPower:) Then go to other ops and add this code:
n: t1 toPower: t2
^ t1 raisedTo: t2
Save the image. There is now a new block in operators (the exponentiation block). Now for your first test. Try to make true and false Boolean reporters using the skills taught in this book so far. They should go into the operators category. If you give up, you can look at the bottom of the page for solutions. If there are errors, you should make sure the block type is a Boolean reporter. Also make sure that the ‘t’ on true and the ‘f’ on false are lowercase.
You have coded three types of blocks so far. The two shapes of blocks that you haven’t coded yet are a hat block and a C-block. These are much harder to code as C-blocks are always special form, and hat blocks need much more code than normal and do not have a particular form. In the next chapter, you will code a hat block, but you will code a C-block now.
First, add this block spec:
(‘launch’ #c #doLaunchScript)
Next, navigate to Scratch-Execution Engine -> ScratchProcess -> instance -> private-special forms, and add this code:
doLaunchScript
| t1 |
t1 _ stackFrame expression.
self popStackFrame.
self pushStackFrame: (ScratchStackFrame new expression: t1 firstBlockList)
This C-block runs the script within. It works like a broadcast, except without the extra lag. Save the image. The next block to be added will be the errorless divide block. Add this block spec:
(‘%n / %n errorless’ #r #divNoError:by: 10 0)
The code for this block should be this:
divNoError: t1 by: t2
t2 = 0 ifTrue: [^ nil].
^ t1 / t2
Save the image (as usual). Next, try to make a block that will allow Boolean reporters to fit into strings. (A Boolean number reporter.) This is not as easy as it seems.
Here are a few more blocks to add. From now on, I’ll only give the code and block type.
showDialogWithTitle: t1 withText: t2
DialogBoxMorph inform: t2 title: t1
This shows a dialog with a specified title and specified text. It is a command block.
reportError
^ ‘Error!’
This block reports an error. It is (of course) a reporter.
setErrorFlag
errorFlag _ true
This special command block creates an error. The code for this block goes in private-special forms. Soon we will work on some more complicated things. Here is one last block to add:
getTime: t1
t1 = 'date' ifTrue: [^ Date today].
t1 = 'short date' ifTrue: [^ Date today printFormat: #(1 2 3 $- 2 2 )].
t1 = 'time' ifTrue: [^ Time now].
t1 = 'seconds' ifTrue: [^ Time now seconds].
t1 = 'minutes' ifTrue: [^ Time now minutes].
t1 = 'hours' ifTrue: [^ Time now hours].
t1 = 'day' ifTrue: [^ Date today weekday].
t1 = 'help' ifTrue: [^ 'type date, short date, time, seconds, minutes, day, hours'].
^ 'Error!’
This block allows you to get the date or time. It is useful for making a clock in a project. Now let’s move on to more complicated things.
Offline
scratcher7_13 wrote:
I am writing a tutorial book on how to make a Scratch Mod. It's not even close to done yet, and it isn't edited, but I could post some of it. Do you want me to do that?
Great idea! I hope it goes well. Is it going to be published or is it just like a word document?
Offline
Pecola1 wrote:
scratcher7_13 wrote:
I am writing a tutorial book on how to make a Scratch Mod. It's not even close to done yet, and it isn't edited, but I could post some of it. Do you want me to do that?
Great idea! I hope it goes well. Is it going to be published or is it just like a word document?
It is a Word document, but I am hoping to get it published.
Offline
scratcher7_13 wrote:
Pecola1 wrote:
scratcher7_13 wrote:
I am writing a tutorial book on how to make a Scratch Mod. It's not even close to done yet, and it isn't edited, but I could post some of it. Do you want me to do that?
Great idea! I hope it goes well. Is it going to be published or is it just like a word document?
It is a Word document, but I am hoping to get it published.
Do you enjoy writing? Is it a hobby of yours? It is for me! I am the 'best' in my class! (and I wasn't the one who said that
) Interesting, I never looked at a
right before a ) it looks like someone with a big nose
:P)
Offline
scratcher7_13 wrote:
scratcher7_13 wrote:
Chapter 2: Block Specs and Simple Coding
This chapter will focus on how block specs work and teach some simple things about coding in Squeak! You have seen some block specs, so this section should not be too hard. This next section will explain the different parts of a block spec. We will use this block spec as an example: (‘join %s %s’ #r #concatenate:with: ‘hello’ ‘world’). This is the block spec for an existing block, the Join reporter block. The ‘join %s %s’ part is what is shown on the block. The %s is a string inserter. It makes a square on the block that allows text to be typed in to it. There are many other inputs, such as a color inserter and a numerical inserter. These will be discussed soon, but not right now. The #r is the block type. These are the different block types:
#- This is the normal code block.
#b This is a Boolean reporter block.
#r This is a normal reporter block.
#c This is a C block (an iterator.)
#t This is a timed block (like the wait () seconds block.)
#s This is a special form block.
#S This is the When Flag Clicked hat block.
#K This is the When [_] Key Pressed hat block.
#M This is the When Sprite [_] Clicked hat block.
#W This is the When <> Is true hat block.
The last block is obsolete, but it will be added to Sizzle soon. The last part of the block spec, the #concatenate:with: ‘hello’ ‘world’ is the block command. This tells the block to find the ‘concatenate: t1 with: t2’ command and execute the code. The ‘hello’ ‘world’ tells the block what to put into the string inserter as the default strings. There are many different types of inserters (as I said before,) so I won’t list them all here, but the most common ones are:
%s A string inserter.
%n A numerical inserter. (this only excepts numbers.)
%C A color inserter (no palette showing.)
%b A Boolean reporter inserter.
%m A list of sprites.
Soon there will be another inserter and two types of blocks added. I won’t go into much detail about this yet, but we’ll get to it. Next are some simple coding things. First, each code has a heading, and this is how the program finds each section of code. A lot of code in Squeak is referencing other code. Sometimes it’s hard to tell which code are Squeak commands and which are referencing other code. Here are some basics that are good to know for programming blocks.
^ This is the caret symbol. It reports whatever is after it. This is used in all reporter blocks.
* This is the multiplicaion symbol.
+This is the addition symbol.
-This is the subtraction symbol.
/This is the division symbol.
raisedTo: This indicates exponentiation.
|var| This is how variables are declared. It is conventional to use t1, t2, etc. as variable names.
abs: This is the absolute value function.
sqrt: This is the square root function.
=,>,< These compare two expressions.
true This reports true.
false This reports false.
The next block that will be made is the exponentiation reporter. Go to block specs (you know the drill.) Find the reporter section and type this block spec: (‘%n ^ %n’ #r #n:toPower:) Then go to other ops and add this code:
n: t1 toPower: t2
^ t1 raisedTo: t2
Save the image. There is now a new block in operators (the exponentiation block). Now for your first test. Try to make true and false Boolean reporters using the skills taught in this book so far. They should go into the operators category. If you give up, you can look at the bottom of the page for solutions. If there are errors, you should make sure the block type is a Boolean reporter. Also make sure that the ‘t’ on true and the ‘f’ on false are lowercase.
You have coded three types of blocks so far. The two shapes of blocks that you haven’t coded yet are a hat block and a C-block. These are much harder to code as C-blocks are always special form, and hat blocks need much more code than normal and do not have a particular form. In the next chapter, you will code a hat block, but you will code a C-block now.
First, add this block spec:
(‘launch’ #c #doLaunchScript)
Next, navigate to Scratch-Execution Engine -> ScratchProcess -> instance -> private-special forms, and add this code:
doLaunchScript
| t1 |
t1 _ stackFrame expression.
self popStackFrame.
self pushStackFrame: (ScratchStackFrame new expression: t1 firstBlockList)
This C-block runs the script within. It works like a broadcast, except without the extra lag. Save the image. The next block to be added will be the errorless divide block. Add this block spec:
(‘%n / %n errorless’ #r #divNoError:by: 10 0)
The code for this block should be this:
divNoError: t1 by: t2
t2 = 0 ifTrue: [^ nil].
^ t1 / t2
Save the image (as usual). Next, try to make a block that will allow Boolean reporters to fit into strings. (A Boolean number reporter.) This is not as easy as it seems.
Here are a few more blocks to add. From now on, I’ll only give the code and block type.
showDialogWithTitle: t1 withText: t2
DialogBoxMorph inform: t2 title: t1
This shows a dialog with a specified title and specified text. It is a command block.
reportError
^ ‘Error!’
This block reports an error. It is (of course) a reporter.
setErrorFlag
errorFlag _ true
This special command block creates an error. The code for this block goes in private-special forms. Soon we will work on some more complicated things. Here is one last block to add:
getTime: t1
t1 = 'date' ifTrue: [^ Date today].
t1 = 'short date' ifTrue: [^ Date today printFormat: #(1 2 3 $- 2 2 )].
t1 = 'time' ifTrue: [^ Time now].
t1 = 'seconds' ifTrue: [^ Time now seconds].
t1 = 'minutes' ifTrue: [^ Time now minutes].
t1 = 'hours' ifTrue: [^ Time now hours].
t1 = 'day' ifTrue: [^ Date today weekday].
t1 = 'help' ifTrue: [^ 'type date, short date, time, seconds, minutes, day, hours'].
^ 'Error!’
This block allows you to get the date or time. It is useful for making a clock in a project. Now let’s move on to more complicated things.
Tip: Instead of "^ 'Error!'", you can just do "^ self Error" and it will do a proper error.
Offline
rdococ wrote:
scratcher7_13 wrote:
scratcher7_13 wrote:
Chapter 2: Block Specs and Simple Coding
...
This block allows you to get the date or time. It is useful for making a clock in a project. Now let’s move on to more complicated things.Tip: Instead of "^ 'Error!'", you can just do "^ self Error" and it will do a proper error.
![]()
He knows, I told him. But thanks anyways.
Last edited by Pecola1 (2011-05-04 18:00:13)
Offline
ninjaaa wrote:
I want that book
And Blocks are codes? Interesting..
The block itself isn't, only the selector it runs, and it is really called a method.
Offline