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

#1 2011-02-28 10:30:51

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

Squeak Smalltalk Chapter 3

Now what if you want your own dropdown? You may think this would need a lot of coding and lots of methods, but it's actually quite simple. First you will need to go to Scratch-Objects -> ScriptableScratchMorph ( or ScriptableSpriteMorph or ScriptableStageMorph, this time it doesn't matter which one.) Then go to any op (best to use sensing ops if you have a sensing list, sound ops for sound, etc. but it doesn't affect anything.) Now you will make your first code.
    Make it like this:

Code:

yourNameForYourDroppdown
    ^ #('your first item' 'your second item' 'etc.' )

Now go to Scratch-Blocks. Then switch to CommandBlockMorph. Now private. And finally uncoloredArgMorphFor:
    This is where I got the list of inserts I gave you in chapter 2. You will see all of those letters on the side marked:

$oneLetter = t2 ifTrue: [].

Of course I could've just given you that and let you figure out how to find what goes to what but that would've taken longer for you.
    To make your dropdown added add above the

^ ExpressionArgMorph new numExpression: '10'

:

Code:

$yourOneLetter = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #yourNameForYourDropdown].

THE yourOneLetter SHOULD NOT BE ANY OTHER LETTER USED FOR AN INSERT (you can use another case as in UPPERCASE or lowercase)
    How about if you want it to have a default value?

Code:

 $yourOneLetter = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #yourNameForYourDropdown; choice: 'your default choice'].

What if you want a reporter to fit into it?

Code:

 $yourOneLetter = t2 ifTrue: [^ ChoiceOrExpressionArgMorph new getOptionsSelector: #yourNameForYourDropdown;
         choice: 'your default choice'].

If you want it to be a number insert

Code:

$yourOneLetter = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: 'your default number';
         menuSelector: #yourNameForYourDropdown].

If you want a text insert

Code:

 $yourOneLetter = t2 ifTrue: [^ ExpressionArgMorphWithMenu new stringExpression: 'your default string';
         menuSelector: #listsMenu].

DOES NOT ALWAYS WORK.
    Now to test your dropdown, go to block specs (it doesn't matter which one, to test I use ScriptableScratchMorph) make your test block by simply inserting:

('%yourOneLetter' #- #-)

after 'control' (or any other place that names a category) accept. Go to the tab control (or whatever category you put it after) and find your block.
    Example:

http://www.weebly.com/uploads/5/4/1/3/5413503/5478461.png
   
Now let's make a block which includes a custom dropdown, here's a simple one:

http://www.weebly.com/uploads/5/4/1/3/5413503/7920306.png
    Using the information I have given you I want YOU to insert these codes where you think they should go (If you need help post about it):
Method:

Code:

 
reportSingle: t1 
    'infinity' = t1 ifTrue: [^ Float infinity].
    'nil' = t1 ifTrue: [^ nil].
    'pi' = t1 ifTrue: [^ Float pi].
    'phi' = t1 ifTrue: [^ '1.61803399'].
    'e' = t1 ifTrue: [^ Float e].
    'newline' = t1 ifTrue: [^ String crlf].
    'tab' = t1 ifTrue: [^ '    ']

Method2:

Code:

 
singleNames
    ^ #('pi' 'phi' 'e' #- 'newline' 'tab' #- 'infinity' #- 'nil' )

BlockSpecs:

('%A' #r #reportSingle:)

uncoloredArgMorphFor:

Code:

 $A = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #singleNames].

Now go to the Operators category (or wherever you chose to put it), you have now made a new block! Of course you may have seen it in a mod or something, but this is one I have edited and made it look better, and more advanced. Can you add anything else to that list? Do you know how? It is actually quite simple, just add a 'your drop-down  word' in-between the ()'s.

http://www.weebly.com/uploads/5/4/1/3/5413503/3191070.gif
http://www.weebly.com/uploads/5/4/1/3/5413503/3967268.gif
http://www.weebly.com/uploads/5/4/1/3/5413503/8557935.gif

Last edited by Pecola1 (2011-04-24 10:58:49)


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

 

#2 2011-03-01 03:07:54

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Squeak Smalltalk Chapter 3

A couple things:
It is "ops" not "opps"
It is in private, not --all--
...That's it.
Still a great tutorial!

Offline

 

#3 2011-03-01 09:42:05

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

Re: Squeak Smalltalk Chapter 3

scimonster wrote:

A couple things:
It is "ops" not "opps"
It is in private, not --all--
...That's it.
Still a great tutorial!

I know its op not op, I just wasn't looking at the source right then. I also know its under private, it is also under all though, all has all of them.


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

 

#4 2011-03-01 09:47:09

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Squeak Smalltalk Chapter 3

Pecola1 wrote:

scimonster wrote:

A couple things:
It is "ops" not "opps"
It is in private, not --all--
...That's it.
Still a great tutorial!

I know its op not op, I just wasn't looking at the source right then. I also know its under private, it is also under all though, all has all of them.

Why not put it in the original place?

Offline

 

#5 2011-03-01 10:02:31

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

Re: Squeak Smalltalk Chapter 3

scimonster wrote:

Pecola1 wrote:

scimonster wrote:

A couple things:
It is "ops" not "opps"
It is in private, not --all--
...That's it.
Still a great tutorial!

I know its op not op, I just wasn't looking at the source right then. I also know its under private, it is also under all though, all has all of them.

Why not put it in the original place?

IDK. It is quicker to click --all-- than private.


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

 

#6 2011-03-01 10:03:15

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Squeak Smalltalk Chapter 3

Pecola1 wrote:

scimonster wrote:

Pecola1 wrote:


I know its op not op, I just wasn't looking at the source right then. I also know its under private, it is also under all though, all has all of them.

Why not put it in the original place?

IDK. It is quicker to click --all-- than private.

Really?

Offline

 

#7 2011-03-01 10:03:31

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

Re: Squeak Smalltalk Chapter 3

Pecola1 wrote:

scimonster wrote:

Pecola1 wrote:

I know its op not op, I just wasn't looking at the source right then. I also know its under private, it is also under all though, all has all of them.

Why not put it in the original place?

IDK. It is quicker to hit --all-- than private.

Man, that sounds kinda wrong.


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

 

#8 2011-03-01 10:04:33

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

Re: Squeak Smalltalk Chapter 3

scimonster wrote:

Pecola1 wrote:

scimonster wrote:

Why not put it in the original place?

IDK. It is quicker to click --all-- than private.

Really?

--all-- is always on the very top, you do notice we are both on right?


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-03-01 10:05:46

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

Re: Squeak Smalltalk Chapter 3

scimonster wrote:

A couple things:
It is "ops" not "opps"
It is in private, not --all--
...That's it.
Still a great tutorial!

You are like the only one that actually reads these. LOL its kinda sad.


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

 

#10 2011-03-01 10:48:57

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

Re: Squeak Smalltalk Chapter 3

scimonster wrote:

A couple things:
It is "ops" not "opps"
It is in private, not --all--
...That's it.
Still a great tutorial!

Hey! Its under evaluation not private! LOL.


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-03-01 10:50:32

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

Re: Squeak Smalltalk Chapter 3

scimonster wrote:

Still a great tutorial!

I am starting Chap 4!


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

 

#12 2011-03-01 11:15:24

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Squeak Smalltalk Chapter 3

Pecola1 wrote:

scimonster wrote:

Pecola1 wrote:


IDK. It is quicker to click --all-- than private.

Really?

--all-- is always on the very top, you do notice we are both on right?

Yeah. CommandBlockMorph is in the middle though. Why don't you just say both?

Offline

 

#13 2011-03-01 11:16:38

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Squeak Smalltalk Chapter 3

Pecola1 wrote:

scimonster wrote:

A couple things:
It is "ops" not "opps"
It is in private, not --all--
...That's it.
Still a great tutorial!

Hey! Its under evaluation not private! LOL.

Um, Scratch-Blocks -> CommandBlockMorph -> private -> uncoloredArgMorphFor:.

Offline

 

#14 2011-03-01 12:49:31

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

Re: Squeak Smalltalk Chapter 3

scimonster wrote:

Pecola1 wrote:

scimonster wrote:

A couple things:
It is "ops" not "opps"
It is in private, not --all--
...That's it.
Still a great tutorial!

Hey! Its under evaluation not private! LOL.

Um, Scratch-Blocks -> CommandBlockMorph -> private -> uncoloredArgMorphFor:.

Look at the system browser, its Scratch-Blocks -> CommandBlockMorph -> evaluation -> uncoloredArgMorphFor:. Unless you have a different version. Or maybe I changed it on mine, lemme check on one I haven't edited. Hmm... your right, LOL I will have to talk to ssss about this, i was using the RKT System Browser, everything in command block morph is mixed up! Thank you for pointing that out.

Last edited by Pecola1 (2011-03-01 12:49:48)


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

 

#15 2011-03-01 13:01:03

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Squeak Smalltalk Chapter 3

Pecola1 wrote:

scimonster wrote:

Pecola1 wrote:


Hey! Its under evaluation not private! LOL.

Um, Scratch-Blocks -> CommandBlockMorph -> private -> uncoloredArgMorphFor:.

Look at the system browser, its Scratch-Blocks -> CommandBlockMorph -> evaluation -> uncoloredArgMorphFor:. Unless you have a different version. Or maybe I changed it on mine, lemme check on one I haven't edited. Hmm... your right, LOL I will have to talk to ssss about this, i was using the RKT System Browser, everything in command block morph is mixed up! Thank you for pointing that out.

You're welcome.  tongue

Offline

 

#16 2011-04-09 13:12:48

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Squeak Smalltalk Chapter 3

Thanks!

Offline

 

#17 2011-04-09 21:50:46

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

Re: Squeak Smalltalk Chapter 3

ProgrammingFreak wrote:

Thanks!

U R WELCOME.


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

 

#18 2011-04-17 19:17:55

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Squeak Smalltalk Chapter 3

Pecola1 wrote:

Code:

 
reportSingle: t1 
    'infinity' = t1 ifTrue: [^ Float infinity].
    'nil' = t1 ifTrue: [^ nil].
    'pi' = t1 ifTrue: [^ Float pi].
    'phi' = t1 ifTrue: [^ '1.61803399'].
    'e' = t1 ifTrue: [^ Float e].
    'newline' = t1 ifTrue: [^ String crlf].
    'tab' = t1 ifTrue: [^ '    ']

Is this a separate method? If so, can I put code in the code in between the '[ ]''s? Instead of reporting it? I'm making a block that is an upgrade of 'move () steps'. This one allows you to choose which direction you would like to step. I have the code for the direction, now i just gotta make the drop down so i can make it all one block.  big_smile

Offline

 

#19 2011-04-17 19:29:52

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

Re: Squeak Smalltalk Chapter 3

ProgrammingFreak wrote:

Pecola1 wrote:

Code:

 
reportSingle: t1 
    'infinity' = t1 ifTrue: [^ Float infinity].
    'nil' = t1 ifTrue: [^ nil].
    'pi' = t1 ifTrue: [^ Float pi].
    'phi' = t1 ifTrue: [^ '1.61803399'].
    'e' = t1 ifTrue: [^ Float e].
    'newline' = t1 ifTrue: [^ String crlf].
    'tab' = t1 ifTrue: [^ '    ']

Is this a separate method? If so, can I put code in the code in between the '[ ]''s? Instead of reporting it? I'm making a block that is an upgrade of 'move () steps'. This one allows you to choose which direction you would like to step. I have the code for the direction, now i just gotta make the drop down so i can make it all one block.  big_smile

Do you mean the 'move () steps in () direction' block from RKT? If so use %d for the direction insert.


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

 

#20 2011-04-17 19:31:19

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

Re: Squeak Smalltalk Chapter 3

ProgrammingFreak wrote:

Pecola1 wrote:

Code:

 
reportSingle: t1 
    'infinity' = t1 ifTrue: [^ Float infinity].
    'nil' = t1 ifTrue: [^ nil].
    'pi' = t1 ifTrue: [^ Float pi].
    'phi' = t1 ifTrue: [^ '1.61803399'].
    'e' = t1 ifTrue: [^ Float e].
    'newline' = t1 ifTrue: [^ String crlf].
    'tab' = t1 ifTrue: [^ '    ']

Is this a separate method? If so, can I put code in the code in between the '[ ]''s? Instead of reporting it? I'm making a block that is an upgrade of 'move () steps'. This one allows you to choose which direction you would like to step. I have the code for the direction, now i just gotta make the drop down so i can make it all one block.  big_smile

reportSingle and singleNames are separate methods.


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

 

#21 2011-04-17 19:32:03

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Squeak Smalltalk Chapter 3

Pecola1 wrote:

ProgrammingFreak wrote:

Pecola1 wrote:

Code:

 
reportSingle: t1 
    'infinity' = t1 ifTrue: [^ Float infinity].
    'nil' = t1 ifTrue: [^ nil].
    'pi' = t1 ifTrue: [^ Float pi].
    'phi' = t1 ifTrue: [^ '1.61803399'].
    'e' = t1 ifTrue: [^ Float e].
    'newline' = t1 ifTrue: [^ String crlf].
    'tab' = t1 ifTrue: [^ '    ']

Is this a separate method? If so, can I put code in the code in between the '[ ]''s? Instead of reporting it? I'm making a block that is an upgrade of 'move () steps'. This one allows you to choose which direction you would like to step. I have the code for the direction, now i just gotta make the drop down so i can make it all one block.  big_smile

Do you mean the 'move () steps in () direction' block from RKT? If so use %d for the direction insert.

Oh, you guys already made that?  sad

Oh and answer my other question.

Last edited by ProgrammingFreak (2011-04-17 19:32:47)

Offline

 

#22 2011-04-17 19:39:00

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

Re: Squeak Smalltalk Chapter 3

ProgrammingFreak wrote:

Pecola1 wrote:

ProgrammingFreak wrote:


Is this a separate method? If so, can I put code in the code in between the '[ ]''s? Instead of reporting it? I'm making a block that is an upgrade of 'move () steps'. This one allows you to choose which direction you would like to step. I have the code for the direction, now i just gotta make the drop down so i can make it all one block.  big_smile

Do you mean the 'move () steps in () direction' block from RKT? If so use %d for the direction insert.

Oh, you guys already made that?  sad

Oh and answer my other question.

Yes, the []'s are like the C of an if block, you can report or not report. I used to think that it would stop the block if you put a code inside of it. But then I noticed only if you put a report inside will it stop, it will stop whenever you make it report. Silly me.  tongue


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

 

#23 2011-04-17 19:45:29

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Squeak Smalltalk Chapter 3

Pecola1 wrote:

ProgrammingFreak wrote:

Pecola1 wrote:


Do you mean the 'move () steps in () direction' block from RKT? If so use %d for the direction insert.

Oh, you guys already made that?  sad

Oh and answer my other question.

Yes, the []'s are like the C of an if block, you can report or not report. I used to think that it would stop the block if you put a code inside of it. But then I noticed only if you put a report inside will it stop, it will stop whenever you make it report. Silly me.  tongue

Also, can you make variables anywhere?

Offline

 

#24 2011-04-17 19:50:05

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

Re: Squeak Smalltalk Chapter 3

ProgrammingFreak wrote:

Pecola1 wrote:

ProgrammingFreak wrote:


Oh, you guys already made that?  sad

Oh and answer my other question.

Yes, the []'s are like the C of an if block, you can report or not report. I used to think that it would stop the block if you put a code inside of it. But then I noticed only if you put a report inside will it stop, it will stop whenever you make it report. Silly me.  tongue

Also, can you make variables anywhere?

What do you mean make variables anywhere? You mean the watcher allowed off the stage? (yes) Or make a new variable for a certain sprite from another sprite? (yes again) Do you mean make it so the user can make their variable go to motion, control et cetera? (yeperoo) What do you mean?


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

 

#25 2011-04-17 20:02:52

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Squeak Smalltalk Chapter 3

Pecola1 wrote:

ProgrammingFreak wrote:

Pecola1 wrote:


Yes, the []'s are like the C of an if block, you can report or not report. I used to think that it would stop the block if you put a code inside of it. But then I noticed only if you put a report inside will it stop, it will stop whenever you make it report. Silly me.  tongue

Also, can you make variables anywhere?

What do you mean make variables anywhere? You mean the watcher allowed off the stage? (yes) Or make a new variable for a certain sprite from another sprite? (yes again) Do you mean make it so the user can make their variable go to motion, control et cetera? (yeperoo) What do you mean?

Like making variables in between the '||' anywhere? Or is that just at the top?

Offline

 

Board footer