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)
Offline
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']
Offline
I know when I have time Ill improve.
Wrote this at 11pm... the things I do for Scratch
Offline
Add CYOB inputters ($String$)
And loops, like whileTrue:
whileTrue - Repeats while true.
[t1 = 3] whileTrue: [t2 _ t2 + 1]
Offline
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.
Offline
Maybe a complete list of all the block types and input types.
Offline
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)
Offline
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?
Offline
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.
Offline
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?
Offline
johnnydean1 wrote:
yep
Ahhhh... ok.
Meh understands now.
Offline
bbbeb wrote:
This may be in the wrong spot, so sorry.
What does nil mean?![]()
nil, I think is the squeak equivilent of NULL, its 0, false;
Offline
It means the variable has not been set generaly.
Also means 0
Offline
Thanks! I have known about the sorce code but I have never learned how to make blocks of my very own self. Thanks again!
Offline
I am hoping that this will help people, it took me a while...
Offline
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.
Offline
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,
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
sandwich value: 'bread' value: #(topping topping topping).
"or even"
sandwich value: self basicsize asString, ' different kinds!' value: {self. self class}.However, to simply put
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)
Offline
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'):
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)'):
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)
Google it.
Offline
Jwosty wrote:
jonnydean1 wrote:
Scratch stores inputs such as %n as
t1Actually, 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
. 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)
Offline
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?
Offline