I recently began to take an interest in this. I figured out how to make a block, but not how to make it work. Now I'm working on learning Squeak. Just one small, very trivial problem...
I can't figure out how to make a new method.
*waits for laughter to die down*
Seriously, I can't. To my understanding, to make a block:
Go to Scratch Objects > ScratchSpriteMorph or ScratchStageMorph or ScriptableScratchMorph > (any) ops. Then you make a method with your code, and then go to Blockspecs and make your block. Right?
So how do I make the method?
Last edited by Greenatic (2011-06-25 14:47:23)

Offline
Just replace an existing method completely (so with a new name too). It should make a new one, and not over-write the old one (keeping both).
Offline
LS97 wrote:
Just replace an existing method completely (so with a new name too). It should make a new one, and not over-write the old one (keeping both).
I figured out how to rename a category, but not a method. I don't see renaming as a right-click option for a method...how do I replace a method?

Offline
jslomba wrote:
you have to know how to code in squeak. try Scramble, made by hardmath123. that should help you get started.
I know enough. The block I'm trying to code is actually very simple: going to the midpoint in between two coordinates, like this:
go in between x: () y: () and x: () y: ()
(Sorry if somebody has already done this, but I want to do it on my own.)
The blockspec would be:
('go in between x: %n y: %n and x: %n y: %n' #- #(my method here, without parentheses))I think the code would be something like this:
| x1 y1 x2 y2 newX newY | x1_ self reportVar: t1. y1_ self reportVar: t2. x2_ self reportVar: t3. y2_ self reportVar: t4. newX_ (x1 + x2) / 2. newY_ (y1 + y2) / 2. self referencePosition: newX @ newY
But since I'm new, that might be completely wrong. Is it?

Offline
use this:
blockspec
('go in between x: %n y: %n and x: %n y: %n' #- #betweenX:Y:X:Y: '-10' '0' '10' '0')code:
betweenX: t1 Y: t2 X: t3 Y: t4 | newX newY | newX_ (t1 + t2) / 2. newY_ (t3 + t4) / 2. self referencePosition: newX @ newY
Offline
Maybe I should've been more descriptive. Actually navigate to some random method (right place, wrong name) and replace that entire code including title.
Then you can code your own stuff into it.
Offline
LS97 wrote:
Maybe I should've been more descriptive. Actually navigate to some random method (right place, wrong name) and replace that entire code including title.
Then you can code your own stuff into it.
Thanks.
Last edited by Greenatic (2011-06-25 17:32:06)

Offline
jslomba wrote:
use this:
blockspecCode:
('go in between x: %n y: %n and x: %n y: %n' #- #betweenX:Y:X:Y: '-10' '0' '10' '0')code:
Code:
betweenX: t1 Y: t2 X: t3 Y: t4 | newX newY | newX_ (t1 + t2) / 2. newY_ (t3 + t4) / 2. self referencePosition: newX @ newY
Thanks. Was there anything wrong with mine? If there was, I would like to know so I can learn. Or is your just a simplified version?
EDIT: t2 and t3 need to be swapped.
EDIT AGAIN: It won't accept it. "Nothing more expected" appears between newY and arrow.
THIRD EDIT: Ignore the second edit. I forgot the periods.
Last edited by Greenatic (2011-06-25 17:45:01)

Offline
Greenatic wrote:
jslomba wrote:
use this:
blockspecCode:
('go in between x: %n y: %n and x: %n y: %n' #- #betweenX:Y:X:Y: '-10' '0' '10' '0')code:
Code:
betweenX: t1 Y: t2 X: t3 Y: t4 | newX newY | newX_ (t1 + t2) / 2. newY_ (t3 + t4) / 2. self referencePosition: newX @ newYThanks. Was there anything wrong with mine? If there was, I would like to know so I can learn. Or is your just a simplified version?
EDIT: t2 and t3 need to be swapped.
oh, yeah.
it's just simplified with the method name put in.
Offline
There's a problem. I edited my last message because I didn't expect you to reply so quickly (therefore I wouldn't need this message to respond). Check my last message, under "EDIT AGAIN".
EDIT: Never mind, I forgot the periods after some lines.
Last edited by Greenatic (2011-06-25 17:44:06)

Offline
By the way, jslomba, I posted the new block in the Block Library with credit to both of us. I hope you don't mind.

Offline
Another question: How do I use more than one thing in an if statement? like
[t1>1] ifTrue:[(commands here)].
How do I put more than one thing in the (commands here) section?

Offline
jslomba wrote:
you have to press 'enetr' after each command.
Still now working, but I'm using whileTrue, not ifTrue. Could that be affecting it?
Anyway, this is the line of code:
[t1 > 1] whileTrue:[answer_answer*t1 t1_t1-1].
I need to make both commands work. How?

Offline
jslomba wrote:
do this:
Code:
[t1 > 1] whileTrue:[answer_answer*t1 ]. [t1 > 1] whileTrue:[t1_t1-1].
But won't that run the first all the way, then the second all the way? I need them to run simultaneously, because otherwise, if t1 > 1 I have a forever loop.

Offline
jslomba wrote:
do this:
Code:
[t1 > 1] whileTrue:[answer_answer*t1 ]. [t1 > 1] whileTrue:[t1_t1-1].
I just tried yours to see whether it would work. It created a forever loop that froze scratch and sent my CPU crazy. I had to end the task in Task Manager.

Offline
Thanks. I had tried that, and I thought that didn't work...but now it's working. o.O
EDIT: It's not working!!! The do command works with it, but when I try to save it it says it can't store into the second command.
This is the code:
Factorial: t1
| answer |
answer_ 1.
t1 = 0 ifTrue:[^1].
t1 < 0 ifTrue:[^0].
t1 isInf ifTrue:[^0].
t1 isNaN ifTrue:[^0].
[t1 > 1] whileTrue:[answer_answer*t1. t1_t1-1].
^ answerP.S. Is there anything wrong with the title "Factorial: t1"? I think it's right...
Last edited by Greenatic (2011-06-26 09:39:53)

Offline
Please, can someone help me??? Please???

Offline
*bump*

Offline
t1 is a input.
A input can NOT be changed.
The code: t1_t1-1
needs to be adapted. Try this:
Factorial: t10
| t1 answer |
t1_ t10.
answer_ 1.
t1 = 0 ifTrue:[^1].
t1 < 0 ifTrue:[^0].
t1 isInf ifTrue:[^0].
t1 isNaN ifTrue:[^0].
[t1 > 1] whileTrue:[answer_answer*t1. t1_t1-1].
^ answerOffline