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

#201 2012-05-12 15:19:40

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

sparks wrote:

Dreamod, I'm starting work on the block sharing page on the block library! It would be great if you could post a sample code for a stack block with the spec "block name", the code "block code" and soforth so that I can get the form to output a complete block file, ready for importing!

So, if I understand correctly, you want to create a block file generator? I already have that in the block importer but here is a sample block and the code to generate the block file. By the way, clicking help, if there is no help file, brings a dialog with the first comment at the code for the block.

Code:

'From MIT Squeak 0.9.4 (June 1, 2003) [No updates present.] on 12 May 2012 at 9:12:36 pm'!

!ScratchSpriteMorph methodsFor: 'control'!
blockCode
"this block does nothing, the comment here can be used to access help for the block"
^ self
! !
!CustomBlockSpecsDictionary class methodsFor: 'blocks'!
getNewestBlock
    ^ #('Sprites' 'control' ('block name' #- #blockCode))! !

here is how you should generate it:
'Sprites' can also be 'Stage' or 'All'.
('Sprites' 'category' ('block' #- #spec)) //notice the two parentheses at the end.
tell me if you need some help.

Offline

 

#202 2012-05-12 15:36:27

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Block Files

Okay, thanks.

Greenatic, the form I'm building on the website will only display options to select categories that exist in that modification. You can see the work in progress here: http://blocks.scratchr.org/share.php (This needs serious beautifying by someone with time and taste (i.e not me)).

Dreamod, so if I understand correctly, the parts of that file that need to be changed to make a block are:

'From MIT Squeak 0.9.4 (June 1, 2003) [No updates present.] on DATE'!

!ScratchSpriteMorph methodsFor: 'PALLET CATEGORY'!
blockCode
"FUNCTION DESCRIPTION"
INSERT CODE HERE
^ self
! !
!CustomBlockSpecsDictionary class methodsFor: 'blocks'! << does blocks need to be replaced with something?
getNewestBlock
    ^ #('STAGE SPRITE OR ALL' 'PALLET CATEGORY' ('BLOCK NAME' #BLOCK TYPE #blockCode))! !

Does blockCode need to be given a unique link? From my understanding of smalltalk it would...

Last edited by sparks (2012-05-12 15:36:58)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#203 2012-05-12 15:58:11

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

sparks wrote:

Okay, thanks.

Greenatic, the form I'm building on the website will only display options to select categories that exist in that modification. You can see the work in progress here: http://blocks.scratchr.org/share.php (This needs serious beautifying by someone with time and taste (i.e not me)).

Dreamod, so if I understand correctly, the parts of that file that need to be changed to make a block are:

'From MIT Squeak 0.9.4 (June 1, 2003) [No updates present.] on DATE'!

!ScratchSpriteMorph */ you want to replace this if it's not a sprite block, here is how it works: 'Sprites' = ScratchSpriteMorph.
'Stage' = ScratchStageMorph.
'All' = ScriptableScratchMorph. (superclass of the classes mentioned above)./*
methodsFor: 'PALLET CATEGORY'!
blockCode
"FUNCTION DESCRIPTION"
INSERT CODE HERE
^ self <-- this is a place holder code: remove it
! !
!CustomBlockSpecsDictionary class methodsFor: 'blocks'! < does blocks need to be replaced with something? //no
getNewestBlock
    ^ #('STAGE SPRITE OR ALL' 'PALLET CATEGORY' ('BLOCK NAME' #BLOCK TYPE #blockCode */ this is the selector it is required, I made a code (in smalltalk, but I can rewrite it in javascript) to extract this from the code./*) )! !

Does blockCode need to be given a unique link? From my understanding of smalltalk it would...

yes, the third part in the blockspec is a selector, which is used in all programming languages (that I know of) in objective-c it's
- (int)methodName;
or in c
int methodName();

Offline

 

#204 2012-05-12 16:06:22

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Block Files

Okay, cool. How do you recommend I go about uniquely naming each selector? Can it contain numbers? I could use the unique block ID generated when the block is uploaded. For example, if a stack block was uploaded called "invert stage colors" under the looks category and it was the 56th block to be uploaded, I could use one of these for the selector name to make sure they're unique and vaguely descriptive:

isc56 (invert stage colors 56)
-56 (stack, 56)
l56 (looks, 56)
l-56 (looks, stack, 56)

or any combination thereof. Thoughts?

Last edited by sparks (2012-05-12 16:07:02)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#205 2012-05-12 16:09:59

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

sparks wrote:

Okay, cool. How do you recommend I go about uniquely naming each selector? Can it contain numbers? I could use the unique block ID generated when the block is uploaded. For example, if a stack block was uploaded called "invert stage colors" under the looks category and it was the 56th block to be updated, I could use one of these for the selector name:

isc56 (invert stage colors 56)
-56 (stack, 56)
l56 (looks, 56)
l-56 (looks, stack, 56)

or any combination thereof. Thoughts?

Do you know what a selector is? A selector points to a method in code. The selector can't be randomized it must be taken from the first line of the code. Then the variable name must be removed. Say this is the first line of the code.

Code:

do: aBlock to: anObject times: aNumber

the selector must be the same except without the variable names: (aBlock, anObject, aNumber). So it should look like this:

Code:

do:to:times:

Offline

 

#206 2012-05-12 16:15:34

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

Might I suggest on a way to improve the design?
try this: http://s15.postimage.org/4zgx0vuft/Block_Share.png

Offline

 

#207 2012-05-12 16:17:50

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

Re: Block Files

dreamod wrote:

Might I suggest on a way to improve the design?
try this: http://s15.postimage.org/4zgx0vuft/Block_Share.png

That looks nice.  Maybe we should add "cap" as an option too.

Small bug in the patch:  Whenever I open the image, the first time I click the Blocks menu, it asks me if I want to reset the custom blocks and args.

(And maybe you should upload some informational projects on the patch.  It should get you promoted to Scratcher sooner.   smile  )

Last edited by Greenatic (2012-05-12 16:18:59)

Offline

 

#208 2012-05-12 16:22:48

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

Greenatic wrote:

dreamod wrote:

Might I suggest on a way to improve the design?
try this: http://s15.postimage.org/4zgx0vuft/Block_Share.png

That looks nice.  Maybe we should add "cap" as an option too.

Small bug in the patch:  Whenever I open the image, the first time I click the Blocks menu, it asks me if I want to reset the custom blocks and args.

(And maybe you should upload some informational projects on the patch.  It should get you promoted to Scratcher sooner.   smile  )

This should only happen the first time you launch the image, because it has to initialize a few variables. I will add some informational projects soon.

Offline

 

#209 2012-05-12 16:36:47

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Block Files

I think I should add a cap block, yes, good idea!

Dreamod, this is exactly how I want it to look! Right now I'm just coding it together quickly cos I got back from work a few hours ago and I have work again tomorrow so I'm kinda hoping someone will HTML it for me  tongue


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#210 2012-05-12 16:41:07

soniku3
Scratcher
Registered: 2011-12-08
Posts: 1000+

Re: Block Files

sparks wrote:

Hey, Dreamod, this looks pretty amazing! The block library has been looking for something like this for absolutely ages!

[offtopic]How do you have different siggys on every forum? [/offtopic]


internet's all about cats today.

Offline

 

#211 2012-05-12 17:11:51

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Block Files

soniku3 wrote:

sparks wrote:

Hey, Dreamod, this looks pretty amazing! The block library has been looking for something like this for absolutely ages!

[offtopic]How do you have different siggys on every forum? [/offtopic]

It randomly chooses one of three signatures when the page loads (refresh and it will have a 2/3 chance of changing). It uses code from my Self-updating images and links in posts topic and you can use it too! The url for the image in my sig is

Code:

http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://dl.dropbox.com/u/22935223/cheddarSparks.png&link2=http://dl.dropbox.com/u/22935223/bitter-tastic.png&link3=http://dl.dropbox.com/u/22935223/toasters.png

You should be able to see how it works from that - the forum thread documents it all!

[/offtopic]

Dreamod, how would you suggest I best generate a sensible selector from the information given by the user in the form? We can, of course, ask for a selector, but I fear it may mean more people will write selectors in an incorrect format.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#212 2012-05-12 17:45:10

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

Re: Block Files

sparks wrote:

soniku3 wrote:

sparks wrote:

Hey, Dreamod, this looks pretty amazing! The block library has been looking for something like this for absolutely ages!

[offtopic]How do you have different siggys on every forum? [/offtopic]

It randomly chooses one of three signatures when the page loads (refresh and it will have a 2/3 chance of changing). It uses code from my Self-updating images and links in posts topic and you can use it too! The url for the image in my sig is

Code:

http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://dl.dropbox.com/u/22935223/cheddarSparks.png&link2=http://dl.dropbox.com/u/22935223/bitter-tastic.png&link3=http://dl.dropbox.com/u/22935223/toasters.png

You should be able to see how it works from that - the forum thread documents it all!

[/offtopic]

Dreamod, how would you suggest I best generate a sensible selector from the information given by the user in the form? We can, of course, ask for a selector, but I fear it may mean more people will write selectors in an incorrect format.

Like me.   tongue  The first letter of all my selectors is capital.  I did it so that all my methods would be at the top when I went to locate them.

Also, dreamod, it happens every time I open the image.  Is that what it's supposed to do?  And why doesn't it just initialize the variables without the dialog?  The dialog could confuse people, and it doesn't seem to affect functionality whether you say yes or no.

Offline

 

#213 2012-05-12 17:49:15

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Block Files

I mean, I'm not quite sure of the selector syntax. is it just that all arguments are replaced with a : from the blockspec, e.g. wait %n secs becomes wait:secs?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#214 2012-05-12 20:14:31

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

Re: Block Files

sparks wrote:

I mean, I'm not quite sure of the selector syntax. is it just that all arguments are replaced with a : from the blockspec, e.g. wait %n secs becomes wait:secs?

No, the selector can be something totally different, except the variables' location has to match up.we can have a  For example, we can have a block with blockspec 'say %s for %n mins'.  The name of its method is saySomething: aString minTime: aNumber.  The selector in the blockspec would be saySomething:minTime:.

Offline

 

#215 2012-05-12 22:08:50

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Block Files

So, dreamod, did the QL plugin work out?


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#216 2012-05-13 03:56:21

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

sparks wrote:

I think I should add a cap block, yes, good idea!

Dreamod, this is exactly how I want it to look! Right now I'm just coding it together quickly cos I got back from work a few hours ago and I have work again tomorrow so I'm kinda hoping someone will HTML it for me  tongue

That would require an extra code. But I'll make a patch so it only needs a symbol, maybe #u. Normally, there is a method called isStop (cap block) which looks like this:

Code:

isStop
       ^ selector = #doReturn | (selector = #stopAll)

or in java it would look like this:

Code:

public bool isStop() {
       return selector == "doReturn" | selector == "stopAll"}

Offline

 

#217 2012-05-13 03:59:49

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

Greenatic wrote:

sparks wrote:

soniku3 wrote:

[offtopic]How do you have different siggys on every forum? [/offtopic]

It randomly chooses one of three signatures when the page loads (refresh and it will have a 2/3 chance of changing). It uses code from my Self-updating images and links in posts topic and you can use it too! The url for the image in my sig is

Code:

http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://dl.dropbox.com/u/22935223/cheddarSparks.png&link2=http://dl.dropbox.com/u/22935223/bitter-tastic.png&link3=http://dl.dropbox.com/u/22935223/toasters.png

You should be able to see how it works from that - the forum thread documents it all!

[/offtopic]

Dreamod, how would you suggest I best generate a sensible selector from the information given by the user in the form? We can, of course, ask for a selector, but I fear it may mean more people will write selectors in an incorrect format.

Like me.   tongue  The first letter of all my selectors is capital.  I did it so that all my methods would be at the top when I went to locate them.

Also, dreamod, it happens every time I open the image.  Is that what it's supposed to do?  And why doesn't it just initialize the variables without the dialog?  The dialog could confuse people, and it doesn't seem to affect functionality whether you say yes or no.

Ok, when you click it it sends the same message as re-initialize custom block specs. I'll just make a 'silent' method that does the same. I'll also fix that mistake. Clicking save blocks will do the trick though. I think I should make it automatically save blocks  (Smalltalk snapshot: true andQuit: false) when you initialize it.

Offline

 

#218 2012-05-13 04:23:19

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

sparks wrote:

soniku3 wrote:

sparks wrote:

Hey, Dreamod, this looks pretty amazing! The block library has been looking for something like this for absolutely ages!

[offtopic]How do you have different siggys on every forum? [/offtopic]

It randomly chooses one of three signatures when the page loads (refresh and it will have a 2/3 chance of changing). It uses code from my Self-updating images and links in posts topic and you can use it too! The url for the image in my sig is

Code:

http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://dl.dropbox.com/u/22935223/cheddarSparks.png&link2=http://dl.dropbox.com/u/22935223/bitter-tastic.png&link3=http://dl.dropbox.com/u/22935223/toasters.png

You should be able to see how it works from that - the forum thread documents it all!

[/offtopic]

Dreamod, how would you suggest I best generate a sensible selector from the information given by the user in the form? We can, of course, ask for a selector, but I fear it may mean more people will write selectors in an incorrect format.

This is how you should do it:
The user submits a code right?
so the first line of the code can be turned into the selector for the block.
First you need to break it up into words in an array.
eg:
"say: aString for: aTime times: aNumber"
{"say:" , "aString" , "for:" , "aTime" , "times:" , "aNumber"}
notice that if a selector has arguments it must end with this character ':' .
So you would then use a block closure which goes through every item of the array and skips words not ending with the character ':'. It the size is 1 (or in java: selector.size() == 0) than it reports the first word.

Offline

 

#219 2012-05-13 04:56:52

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

I'm making the upload dialog feature, so far I have the dialog and the selection in the right button menu. Here is a picture http://s17.postimage.org/l0wr1r9ul/Upload_Dialog.png
It takes the information from the block when sending.
The password, as you can see, is shown like this '*******' instead of 'password'.
Would typing guest be a problem for you? It is a risk for spam but I think everybody should have the right to share their blocks.

Offline

 

#220 2012-05-13 05:37:55

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

Hardmath123 wrote:

So, dreamod, did the QL plugin work out?

Not really.

Offline

 

#221 2012-05-13 05:49:15

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: Block Files

sparks wrote:

...so I'm kinda hoping someone will HTML it for me  tongue

Will this do?  smile
You need blocks.gif, too.

(I don't really have any time, but I like to suppose I have a little taste.  tongue )

Last edited by blob8108 (2012-05-13 05:50:05)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#222 2012-05-13 05:51:58

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

this adds additional cap block support
just go to your cap blocks and replace the #- with #u (on stop all) and #y (on stop script)

Code:

'From MIT Squeak 0.9.4 (June 1, 2003) [No updates present.] on 13 May 2012 at 11:49:13 am'!
!BlockMorph subclass: #CommandBlockMorph
    instanceVariableNames: 'isStop commandSpec argPermutation argMorphs titleMorph receiver selector isReporter isTimed wantsName wantsPossession numberArgFlags '
    classVariableNames: 'ArgMorphsDictionary NotWatcherBlocks '
    poolDictionaries: ''
    category: 'Scratch-Blocks'!
!CommandBlockMorph methodsFor: 'private' stamp: 'dreamod 5/13/2012 11:45'!
isStop
    ^ isStop! !

!CommandBlockMorph methodsFor: 'private' stamp: 'dreamod 5/13/2012 11:45'!
isStop: t1
       isStop _ t1! !

!ScriptableScratchMorph methodsFor: 'blocks' stamp: 'dreamod 5/13/2012 11:48'!
blockFromSpec: t1 color: t2 
    | t3 t4 t5 t6 t7 t8 t9 |
    t3 _ ScratchTranslator translationFor: (t1 at: 1).
    t9 _ CommandBlockMorph argPermutationForSpec: (t1 at: 1)
                withTranslation: t3.
    t4 _ t1 at: 2.
    t5 _ (t1 at: 3) asSymbol.
    t6 _ self defaultArgsFor: t1.
    (#(#E #K #M #S #W ) includes: t4)
        ifTrue: [^ (self hatBlockType: t4)
                color: t2].
    (t4 includes: $c)
        ifTrue: [t5 = #doIfElse
                ifTrue: [t7 _ IfElseBlockMorph new isSpecialForm: true]
                ifFalse: [t7 _ CBlockMorph new isSpecialForm: true]]
        ifFalse: [(t4 includes: $r)
                | (t4 includes: $b)
                ifTrue: [t7 _ ReporterBlockMorph new]
                ifFalse: [t7 _ CommandBlockMorph new]].
    (t4 includes: $b)
        ifTrue: [t7 isBoolean: true].
    (t4 includes: $s)
        ifTrue: [t7 isSpecialForm: true].
    (t4 includes: $u)
        ifTrue: [t7 isStop: true].
        (t4 includes: $y)
        ifTrue: [t7 isStop: true; isSpecialForm: true].
    (t4 includes: $t)
        ifTrue: [t7 isTimed: true].
    (ScriptableScratchMorph isSpriteSpecificTarget: self selector: t5)
        ifTrue: [t8 _ self]
        ifFalse: [t8 _ self ownerThatIsA: ScratchStageMorph].
    ^ t7 argPermutation: t9;
     color: t2;
     selector: t5;
     commandSpec: t3;
     defaultArgs: t6;
     receiver: t8! !

Offline

 

#223 2012-05-13 06:54:24

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

Sparks, I ripped a few images for you, they can be downloaded here:
http://www.mediafire.com/?255hmqz8nmm282x

Offline

 

#224 2012-05-13 08:06:31

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

Re: Block Files

Dreamod, I tried filing in your patch and got a "Message not understood: scanFrom:" error.   hmm   Do I need to file it into a new Scratch image or my Block Library image?

Offline

 

#225 2012-05-13 08:15:27

dreamod
New Scratcher
Registered: 2012-01-22
Posts: 100+

Re: Block Files

Greenatic wrote:

Dreamod, I tried filing in your patch and got a "Message not understood: scanFrom:" error.   hmm   Do I need to file it into a new Scratch image or my Block Library image?

whoops, I have one exclamation marks too many! Too bad I can't edit my posts, well remove the first exclamation mark on the second line, that should do the trick.

Offline

 

Board footer