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

#1 2011-06-25 14:47:07

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Please Help a New Blockmaker...

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

 

#2 2011-06-25 14:57:22

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Please Help a New Blockmaker...

you have to know how to code in squeak. try Scramble, made by hardmath123. that should help you get started.


the the the the the

Offline

 

#3 2011-06-25 15:00:11

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Please Help a New Blockmaker...

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

 

#4 2011-06-25 15:06:53

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

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

 

#5 2011-06-25 15:22:57

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

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:

Code:

 ('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:

Code:

 
| 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

 

#6 2011-06-25 15:29:44

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Please Help a New Blockmaker...

use this:

blockspec

Code:

('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

the the the the the

Offline

 

#7 2011-06-25 16:32:43

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Please Help a New Blockmaker...

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

 

#8 2011-06-25 17:31:51

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

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

 

#9 2011-06-25 17:33:04

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

jslomba wrote:

use this:

blockspec

Code:

('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.   tongue

Last edited by Greenatic (2011-06-25 17:45:01)

Offline

 

#10 2011-06-25 17:40:36

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Please Help a New Blockmaker...

Greenatic wrote:

jslomba wrote:

use this:

blockspec

Code:

('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.

oh, yeah.

it's just simplified with the method name put in.


the the the the the

Offline

 

#11 2011-06-25 17:42:53

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

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

 

#12 2011-06-25 18:35:44

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

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

Offline

 

#13 2011-06-25 18:49:51

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Please Help a New Blockmaker...

Greenatic wrote:

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

that's fine!


the the the the the

Offline

 

#14 2011-06-25 19:42:27

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

Another question: How do I use more than one thing in an if statement?  like

Code:

 [t1>1] ifTrue:[(commands here)].

How do I put more than one thing in the (commands here) section?

Offline

 

#15 2011-06-25 21:39:19

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Please Help a New Blockmaker...

you have to press 'enetr' after each command.


the the the the the

Offline

 

#16 2011-06-25 22:14:58

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

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:

Code:

[t1 > 1] whileTrue:[answer_answer*t1 t1_t1-1].

I need to make both commands work.  How?

Offline

 

#17 2011-06-25 22:40:31

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Please Help a New Blockmaker...

do this:

Code:

[t1 > 1] whileTrue:[answer_answer*t1 ].
[t1 > 1] whileTrue:[t1_t1-1].

the the the the the

Offline

 

#18 2011-06-25 23:04:45

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

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

 

#19 2011-06-25 23:11:11

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

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

 

#20 2011-06-26 06:35:34

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Please Help a New Blockmaker...

Code:

[t1 > 1] whileTrue:[answer_answer*t1. t1_t1-1].

(notice the dot between the instructions.)
*code not tested*

Offline

 

#21 2011-06-26 08:18:02

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Please Help a New Blockmaker...

oh yeah, you can just add periods after each command XD


the the the the the

Offline

 

#22 2011-06-26 09:28:27

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

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

This is the code:

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].
    ^ answer

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

 

#23 2011-06-26 17:29:13

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

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

Offline

 

#24 2011-06-27 17:12:14

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please Help a New Blockmaker...

*bump*

Offline

 

#25 2011-06-28 17:47:29

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

Re: Please Help a New Blockmaker...

t1 is a input.
A input can NOT be changed.
The code: t1_t1-1
needs to be adapted. Try this:

Code:

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].
    ^ answer

You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer