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

#1 2010-06-29 16:33:53

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Squeak (Source Code) Guide

It has come to my attention that a lot of people are currently making mods and/or experimenting and making blocks.

I recomend CYOB (In Panther) for individual blocks as it makes it easy to edit.
If you are making a mod use the source code (Drag the image on to the Scratch ShortCut) Source Code

Block Specs

CYOB DOES NOT NEED THIS!

Block Specs are how the block is made. Every block in Scratch has one. They are a essential part and this is what they look like.

( 'BlockName'            r          WhatToDo)

^This is the^  ^Block Type^ ^What to do^
    name of                           when its
   the block                             run

As you can see this is quite easy. Now the diffrent types:

Block Types:
r        Reporter, like a variable shape (ROUNDED)
b       Booleen, these are the <> shaped Blocks. These report true/false
-        Command, normal blocks, eg the Wait 1 secs block

Variables:
%s or $String$       Gives you a input box for text and numbers
%n or $Number$    Gives you a input box for numbers only
%v or $Variable$    Give you a varibale dropdown
%L or $List$          Gives you a list dropdown
%c or $Color$        Gives a colour selector

* Second collum are in CYOB
There are more but I will not put them here.

So you could have:

( 'Select colour %c'     r      colourselect)



How to program blocks
This is harder. This is how a block works e.g the bit I have labled 'WhatToDo'. I am only writeing a quick bit on this as I have to go but here goes.

Scratch stores inputs such as %n as
t1
if you had %n and %L in the same block it would have
t1
t2
made as
t1 = %n
t2 = %L

get it?

So you decleare any other variables in the | zone |

So:

|variables-here space-to-seperate|

This leaves the variables:
variables-here
space-to-seperate

Now to set them

you use a _ sign to set variables so

I have:
|var1|
var1_'hello'.
^var1

This is a very basic block.
|var1| <-- makes the variable var1
var1_ 'hello'. <--- sets 'Var1' to 'hello'
^var1 <---- reports 'var1'

so this is a 'r' or 'b' type block.

So you have learnt that:
_ set variables
^ reports something
' text ' are used to imput text into Squeak
| variable | is used to make a varibale

Other Squeakers please expand ill write more later!

Last edited by johnnydean1 (2010-07-09 11:23:28)


You can now reach me on Twitter @johnnydean1_

Offline

 

#2 2010-06-29 17:08:51

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: Squeak (Source Code) Guide

here are some other things you should add:

ifTrue  -   if the variable it procedes is true (usually the variable representing a boolean) it does/reports what follows it. Used like this:

variable = 10 ifTrue: [^ 'the variable is 10']


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#3 2010-06-30 03:29:16

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Squeak (Source Code) Guide

I know when I have time Ill improve.
Wrote this at 11pm... the things I do for Scratch


You can now reach me on Twitter @johnnydean1_

Offline

 

#4 2010-07-01 10:10:37

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Squeak (Source Code) Guide

Add CYOB inputters ($String$)


And loops, like whileTrue:

whileTrue - Repeats while true.

[t1 = 3] whileTrue: [t2 _ t2 + 1]


http://i46.tinypic.com/dw7zft.png

Offline

 

#5 2010-07-01 12:30:39

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Squeak (Source Code) Guide

Done the first bit already but here:

Guide Continued
In squeak you can also use special statments, such as whileTrue: or ifTrue: use them as shown.

[t1 = 3] whileTrue:
[
code
].

t1 = 4
ifTrue: [
code
]
ifFalse: [
code
].

Also

t3 timesRepeat: [
code
].

will repeat the code the value of t3 number of times.


You can now reach me on Twitter @johnnydean1_

Offline

 

#6 2010-07-01 13:29:34

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Squeak (Source Code) Guide

Maybe a complete list of all the block types and input types.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#7 2010-07-01 19:03:52

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Squeak (Source Code) Guide

johnnydean1 wrote:

Done the first bit already but here:

Guide Continued
In squeak you can also use special statments, such as whileTrue: or ifTrue: use them as shown.

[t1 = 3] whileTrue:
[
code
].

t1 = 4
ifTrue: [
code
]
ifFalse: [
code
].

Also

t3 timesRepeat: [
code
].

will repeat the code the value of t3 number of times.

Those aren't special statements, they're just messages received by Boolean objects. (or blocks or numbers)

Last edited by nXIII (2010-07-01 19:04:27)


nXIII

Offline

 

#8 2010-07-02 04:42:48

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Squeak (Source Code) Guide

nXIII wrote:

johnnydean1 wrote:

Done the first bit already but here:

Guide Continued
In squeak you can also use special statments, such as whileTrue: or ifTrue: use them as shown.

[t1 = 3] whileTrue:
[
code
].

t1 = 4
ifTrue: [
code
]
ifFalse: [
code
].

Also

t3 timesRepeat: [
code
].

will repeat the code the value of t3 number of times.

Those aren't special statements, they're just messages received by Boolean objects. (or blocks or numbers)

Well there not basic code either. but are the square brackets needed?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#9 2010-07-03 16:06:06

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Squeak (Source Code) Guide

How do you stop it if its false? doReturn or something like that?


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#10 2010-07-03 16:23:44

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Squeak (Source Code) Guide

markyparky56 wrote:

nXIII wrote:

johnnydean1 wrote:

Done the first bit already but here:

Guide Continued
In squeak you can also use special statments, such as whileTrue: or ifTrue: use them as shown.

[t1 = 3] whileTrue:
[
code
].

t1 = 4
ifTrue: [
code
]
ifFalse: [
code
].

Also

t3 timesRepeat: [
code
].

will repeat the code the value of t3 number of times.

Those aren't special statements, they're just messages received by Boolean objects. (or blocks or numbers)

Well there not basic code either. but are the square brackets needed?

The brackets indicate blocks. See my thread for info on blocks.


nXIII

Offline

 

#11 2010-07-03 16:36:13

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Squeak (Source Code) Guide

nXIII wrote:

markyparky56 wrote:

nXIII wrote:

Those aren't special statements, they're just messages received by Boolean objects. (or blocks or numbers)

Well there not basic code either. but are the square brackets needed?

The brackets indicate blocks. See my thread for info on blocks.

As in places to put code?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#12 2010-07-03 16:37:23

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Squeak (Source Code) Guide

yep


You can now reach me on Twitter @johnnydean1_

Offline

 

#13 2010-07-03 16:38:59

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Squeak (Source Code) Guide

johnnydean1 wrote:

yep

Ahhhh... ok.  smile  Meh understands now.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#14 2010-07-04 22:32:12

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Squeak (Source Code) Guide

This may be in the wrong spot, so sorry.

What does nil mean?  sad

Last edited by bbbeb (2010-07-04 22:32:43)


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#15 2010-07-05 12:08:20

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Squeak (Source Code) Guide

bbbeb wrote:

This may be in the wrong spot, so sorry.

What does nil mean?  sad

nil, I think is the squeak equivilent of NULL, its 0, false;


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#16 2010-07-05 12:11:38

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Squeak (Source Code) Guide

It means the variable has not been set generaly.

Also means 0


You can now reach me on Twitter @johnnydean1_

Offline

 

#17 2010-07-05 12:21:34

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

Re: Squeak (Source Code) Guide

bbbeb wrote:

How do you stop it if its false? doReturn or something like that?

Code:

someBoolean ifTrue: 
[ bleh bleh bleh ] 
ifFalse: 
[ ^ self ]

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

 

#18 2010-07-05 12:28:48

celloguy123
Scratcher
Registered: 2009-01-15
Posts: 100+

Re: Squeak (Source Code) Guide

Thanks! I have known about the sorce code but I have never learned how to make blocks of my very own self. Thanks again!


http://internetometer.com/image/33068.png

Offline

 

#19 2010-07-06 03:09:15

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Squeak (Source Code) Guide

I am hoping that this will help people, it took me a while...


You can now reach me on Twitter @johnnydean1_

Offline

 

#20 2010-07-06 07:03:11

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Squeak (Source Code) Guide

johnnydean1 wrote:

I am hoping that this will help people, it took me a while...

Maybe some more stuff like examples on how to do certin things which can be added/adapt to work.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#21 2010-07-06 18:22:27

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Squeak (Source Code) Guide

You should definitely change the title to Scratch (source code) Guide. This is more a Scratch Source Code tutorial than a Squeak tutorial.


nXIII

Offline

 

#22 2010-07-06 18:30:33

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Squeak (Source Code) Guide

johnnydean1 wrote:

yep

I'm not really sure what you meant here. I'll explain.

markyparky56 wrote:

nXIII wrote:

markyparky56 wrote:

Well there not basic code either. but are the square brackets needed?

The brackets indicate blocks. See my thread for info on blocks.

As in places to put code?

As in unevaluated code. For example,

Code:

sandwich := [:bread :toppings | {'Bread: ', bread asString. 'Toppings: ', toppings asArray asString}].

This tells me how to make a sandwich (array with two strings, "Bread: bread_type" and "Toppings: toppings") with just the toppings and bread given. I can do this as many times as I want with whatever things I want by simply typing

Code:

sandwich value: 'bread' value: #(topping topping topping).
"or even"
sandwich value: self basicsize asString, ' different kinds!' value: {self. self class}.

However, to simply put

Code:

bread := 'Wheat'.
toppings := #(cheese lettuce tomato).
sandwich := {'Bread: ', bread. 'Toppings: ', toppings}.

would only give me one sandwich, and I wouldn't know how to make another one of a different type without doing all that again manually.

Last edited by nXIII (2010-07-06 18:32:08)


nXIII

Offline

 

#23 2010-08-06 18:05:45

Jwosty
Scratcher
Registered: 2009-12-19
Posts: 500+

Re: Squeak (Source Code) Guide

jonnydean1 wrote:

Scratch stores inputs such as %n as
t1

Actually, the temporary variables (such as t1) only appear as t1, t2, t3 etc. in the decompiled image. for example, here is the decompiled version of the costume index method (The one you would find in 'scratch.image'):

Code:

costumeIndex: t1 
    | t2 t3 t4 |
    t2 _ media reject: [:t5 | t5 isSound].
    t2 size = 0 ifTrue: [^ self].
    t3 _ t1 rounded - 1 \\ t2 size + 1.
    t4 _ t2 at: t3.
    costume == t4 ifFalse: [self lookLike: t4 mediaName]

And this is the original (The one you would find in: 'Scratch 1.4 (source code of 23-Sep-09)'):

Code:

costumeIndex: aNumber
    "Set my costume to the costume at the given index modulo my total number of costumes. Costumes are numbered starting at 1."

    | cList i newC |
    cList _ media reject: [:m | m isSound].
    cList size = 0 ifTrue: [^ self].  "should never happen..."
    i _ ((aNumber rounded - 1) \\ cList size) + 1.
    newC _ cList at: i.
    costume == newC ifFalse: [self lookLike: newC mediaName].

These are the same method.

The computer just doesn't care about the comments or the names of the temporary variables ('t1' stands for temporary1).

Last edited by Jwosty (2010-08-06 18:06:08)


http://i39.tinypic.com/18ert5.png Google it.  smile

Offline

 

#24 2010-08-06 20:49:39

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Squeak (Source Code) Guide

Jwosty wrote:

jonnydean1 wrote:

Scratch stores inputs such as %n as
t1

Actually, the temporary variables (such as t1) only appear as t1, t2, t3 etc. in the decompiled image. for example, here is the decompiled version of the costume index method (The one you would find in 'scratch.image'):

Code:

costumeIndex: t1 
    | t2 t3 t4 |
    t2 _ media reject: [:t5 | t5 isSound].
    t2 size = 0 ifTrue: [^ self].
    t3 _ t1 rounded - 1 \\ t2 size + 1.
    t4 _ t2 at: t3.
    costume == t4 ifFalse: [self lookLike: t4 mediaName]

And this is the original (The one you would find in: 'Scratch 1.4 (source code of 23-Sep-09)'):

Code:

costumeIndex: aNumber
    "Set my costume to the costume at the given index modulo my total number of costumes. Costumes are numbered starting at 1."

    | cList i newC |
    cList _ media reject: [:m | m isSound].
    cList size = 0 ifTrue: [^ self].  "should never happen..."
    i _ ((aNumber rounded - 1) \\ cList size) + 1.
    newC _ cList at: i.
    costume == newC ifFalse: [self lookLike: newC mediaName].

These are the same method.

The computer just doesn't care about the comments or the names of the temporary variables ('t1' stands for temporary1).

Scratch actually doesn't "store" the inputs as all, it simply calls the block's selector with the arguments as, well, arguments  tongue . The fact that they are "t1", "t2", etc. is because the method is (I believe) being extracted from the actual method (I forget what the class name is)


nXIII

Offline

 

#25 2010-08-07 07:17:24

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Squeak (Source Code) Guide

nXIII wrote:

johnnydean1 wrote:

yep

I'm not really sure what you meant here. I'll explain.

markyparky56 wrote:

nXIII wrote:


The brackets indicate blocks. See my thread for info on blocks.

As in places to put code?

As in unevaluated code. For example,

Code:

sandwich := [:bread :toppings | {'Bread: ', bread asString. 'Toppings: ', toppings asArray asString}].

This tells me how to make a sandwich (array with two strings, "Bread: bread_type" and "Toppings: toppings") with just the toppings and bread given. I can do this as many times as I want with whatever things I want by simply typing

Code:

sandwich value: 'bread' value: #(topping topping topping).
"or even"
sandwich value: self basicsize asString, ' different kinds!' value: {self. self class}.

However, to simply put

Code:

bread := 'Wheat'.
toppings := #(cheese lettuce tomato).
sandwich := {'Bread: ', bread. 'Toppings: ', toppings}.

would only give me one sandwich, and I wouldn't know how to make another one of a different type without doing all that again manually.

So its making a class?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

Board footer