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

#1 2011-04-30 09:46:57

PythonLibrary
Scratcher
Registered: 2011-03-26
Posts: 100+

Help Learning Squeak

The tutorial on the Scratch Wiki is confusing. Can someone post a kid friendly tutorial?


http://dl.dropbox.com/u/9137793/Python%20Library%20logo.png
Our website: pylibrary.co.cc http://dl.dropbox.com/u/9137793/Awesomeness%20Block.gif

Offline

 

#2 2011-04-30 14:43:04

PythonLibrary
Scratcher
Registered: 2011-03-26
Posts: 100+

Re: Help Learning Squeak

B U M P


http://dl.dropbox.com/u/9137793/Python%20Library%20logo.png
Our website: pylibrary.co.cc http://dl.dropbox.com/u/9137793/Awesomeness%20Block.gif

Offline

 

#3 2011-04-30 14:48:14

scratcher7_13
Scratcher
Registered: 2011-02-09
Posts: 1000+

Re: Help Learning Squeak

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?


♫ 90% of teens can't do math. If you are one of the 40% of teens who can, copy and paste this into your signature. ♫♪
http://dl.dropbox.com/u/6273449/BlockLibraryTitle.pnghttp://i.imgur.com/mr9Hf.gif

Offline

 

#4 2011-04-30 14:52:07

PythonLibrary
Scratcher
Registered: 2011-03-26
Posts: 100+

Re: Help Learning Squeak

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.


http://dl.dropbox.com/u/9137793/Python%20Library%20logo.png
Our website: pylibrary.co.cc http://dl.dropbox.com/u/9137793/Awesomeness%20Block.gif

Offline

 

#5 2011-04-30 14:56:59

scratcher7_13
Scratcher
Registered: 2011-02-09
Posts: 1000+

Re: Help Learning Squeak

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.


♫ 90% of teens can't do math. If you are one of the 40% of teens who can, copy and paste this into your signature. ♫♪
http://dl.dropbox.com/u/6273449/BlockLibraryTitle.pnghttp://i.imgur.com/mr9Hf.gif

Offline

 

#6 2011-04-30 20:13:31

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: Help Learning Squeak

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?


If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

#7 2011-04-30 20:52:13

scratcher7_13
Scratcher
Registered: 2011-02-09
Posts: 1000+

Re: Help Learning Squeak

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.


♫ 90% of teens can't do math. If you are one of the 40% of teens who can, copy and paste this into your signature. ♫♪
http://dl.dropbox.com/u/6273449/BlockLibraryTitle.pnghttp://i.imgur.com/mr9Hf.gif

Offline

 

#8 2011-05-01 18:20:12

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: Help Learning Squeak

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.

smile  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  tongue ) Interesting, I never looked at a   tongue  right before a ) it looks like someone with a big nose

Code:

:P)

If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

#9 2011-05-04 16:32:21

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

Re: Help Learning Squeak

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

Offline

 

#10 2011-05-04 17:59:46

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: Help Learning Squeak

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

He knows, I told him. But thanks anyways.  wink

Last edited by Pecola1 (2011-05-04 18:00:13)


If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

#11 2011-05-04 18:05:56

ninjaaa
Scratcher
Registered: 2011-05-01
Posts: 63

Re: Help Learning Squeak

I want that book  wink  And Blocks are codes? Interesting..

Offline

 

#12 2011-05-04 18:16:20

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: Help Learning Squeak

ninjaaa wrote:

I want that book  wink  And Blocks are codes? Interesting..

The block itself isn't, only the selector it runs, and it is really called a method.


If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

Board footer