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

#26 2010-10-27 16:35:31

zorket
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: New types of blocks wanted!

To fit C blocks into strings:
Go to scratchBlocks > commandBlockMorph > all > add a code:

Code:

isReporter
^ true

With just only a few flaws:
1. All the existing C blocks become reporters.
2. It still has it's regular shape.
3. It doesn't report stuff, it just keeps running, often freezing scratch.
4. It doesn't fit command blocks inside of it.
Cool Stuff:
1. It fits into strings!
2. It has boxes next to them!

Last edited by zorket (2010-10-28 08:07:27)


Marzipan11 must learn to not spoil

Offline

 

#27 2010-10-28 17:04:11

zorket
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: New types of blocks wanted!

Oh, c'mon people! I need help with code trades with CBlockMorph and ReporterBlockMorph!


Marzipan11 must learn to not spoil

Offline

 

#28 2010-11-04 07:59:57

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

Re: New types of blocks wanted!

Right, you figured out how to make them fit in alright. If you dont mind having a little bit sticking out, I can easily help you. Not giving you too much info, of course!

So, to start off, you'll want to make a brand new block type for command blocks which report something. Do this in ScriptableScratchMorph's blockFromSpec:color: method. Basically, to make it easy, replace the whole thing with the code below. dont do it just yet though, because we'll need to add a couple methods to CBlockMorph!

Code:

blockFromSpec: spec color: blockColor
    "Create a block from the given block specification. Answer nil if I don't implement the block spec selector."

    | blockLabelSpec blockType selector defaultArgs block rcvr argPermutation |
    blockLabelSpec _ ScratchTranslator translationFor: (spec at: 1).
    argPermutation _ CommandBlockMorph argPermutationForSpec: (spec at: 1) withTranslation: blockLabelSpec.
    blockType _ spec at: 2.
    selector _ (spec at: 3) asSymbol.
    defaultArgs _ self defaultArgsFor: spec.

    (#(E K M S W B) includes: blockType) ifTrue: [
        ^ (self hatBlockType: blockType) color: blockColor].

    "basic block type: normal or C-shaped"
    (blockType includes: $c)
        ifTrue:    [
            selector = #doIfElse
                ifTrue: [block _ IfElseBlockMorph new isSpecialForm: true]
                ifFalse: [block _ CBlockMorph new isSpecialForm: true]]
        ifFalse:    [
            (blockType includes: $r) | (blockType includes: $b)
                ifTrue: [block _ ReporterBlockMorph new]
                ifFalse: [(blockType includes: $m) ifTrue: [^ CBlockMorph new isReporter: true]
                        ifFalse: [block _ CommandBlockMorph new]]].

    (blockType includes: $b) ifTrue: [block isBoolean: true].
    (blockType includes: $s) ifTrue: [block isSpecialForm: true].
    (blockType includes: $t) ifTrue: [block isTimed: true].

    (ScriptableScratchMorph isSpriteSpecificTarget: self selector: selector)
        ifTrue: [rcvr _ self]
        ifFalse: [rcvr _ self ownerThatIsA: ScratchStageMorph].

    ^ block
        argPermutation: argPermutation;
        color: blockColor;
        selector: selector;
        commandSpec: blockLabelSpec;
        defaultArgs: defaultArgs;
        receiver: rcvr

and these methods are:
navigate to CBlockMorph in Scratch-Blocks. add an instance variable called isRep. Wait for the whole thing to recompile.

then, under accessing, add the method below:

isReporter: aBool
isRep _ aBool

now you can replace the code in ScriptableScratchMorph successfully!

after this, we need to take care of whether strings and other arguments accept the block. (by the way, if you want the fancy block tip taken away, you'll have to edit the drawBottomBarOn: method i think)

to do this, we'll need to add yet another method called isReporter to the CBlockMorph (wherever you want)

code:
isReporter
^ isRep

and that should do it.

but, if you were too impatient to wait until this bit and tried to click the block and see what it did, you'll have been a bit disappointed that it just ran and (probably) reported an error. so we'll need to add another little bit of code. this time in the CBlockMorph's category 'private'.

evaulate
self isRep = true ifTrue: [^ self submorphs asString].
super evaulate

that makes it report whatever it has in it (as a string) if it is set to report, otherwise does its normal job!

NOTE: this is all untested theory. sorry if it doesnt work!

now, if you try using the #m block type it should work as you want it to. that is:
.::example block spec::.
('testing this block' m yourself)

i hope it really does work...
btw, you can change that line above highlited in blue if you should ever need the reported stuff to be a picture or something  big_smile

Last edited by LS97 (2010-11-04 08:24:00)

Offline

 

#29 2010-11-04 08:20:42

zorket
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: New types of blocks wanted!

To get the bottom edge smooth, replace drawBottomBarOn: t1 in the drawing for CBlockMorph, with the following:

Code:

drawBottomBarOn: aCanvas 
    | left barTop barBottom |
    (self isForever or: [self isReporter])
        ifTrue: [
            barBottom _ self bottom - 3.
            self drawSmoothBottomEdgeOn: aCanvas]
        ifFalse: [
            barBottom _ self bottom - 7.
            self drawBottomEdgeOn: aCanvas].
    barTop _ barBottom - (CBlockBracketThickness - 3).
    left _ self left + CBlockBracketThickness - 1.
    "fill in bottom-left corner"
    aCanvas fillRectangle: (left - 11@(barTop + 5) extent: 11@4) color: color.
    aCanvas fillRectangle: (left@(barTop - 2) extent: 1@1) color: color.
    aCanvas fillRectangle: (left@(barTop - 1) extent: 2@1) color: color.
    aCanvas fillRectangle: (left@barTop extent: 3@1) color: color.
    aCanvas
        fillRectangle: ((left + 3)@barTop corner: (self right - 2)@(barTop + 1))
        color: highlightColor1.
    aCanvas
        fillRectangle: (left@(barTop + 1) corner: (self right - 1)@barBottom)
        color: color.
    aCanvas
        fillRectangle: ((self right - 1)@(barTop + 2) corner: self right@barBottom)
        color: shadowColor.

Then go to geometry, and add the code:

Code:

isReporter
^ true

There might be a few flaws, because I didn't test the code.

Last edited by zorket (2010-11-09 08:00:38)


Marzipan11 must learn to not spoil

Offline

 

#30 2010-11-04 08:25:05

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

Re: New types of blocks wanted!

oooooooh....
well, if you got that to work then there you go! you'll have to add a little extra code saying that if it's a reporter it has to draw without bit sticking out, and vice versa!  smile

Offline

 

#31 2010-11-04 16:34:27

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

Re: New types of blocks wanted!

here's the original code

Code:

drawBottomBarOn: aCanvas 

    | left barTop barBottom |
    self isForever
        ifTrue: [
            barBottom _ self bottom - 3.
            self drawSmoothBottomEdgeOn: aCanvas]
        ifFalse: [
            barBottom _ self bottom - 7.
            self drawBottomEdgeOn: aCanvas].

    barTop _ barBottom - (CBlockBracketThickness - 3).
    left _ self left + CBlockBracketThickness - 1.

    "fill in bottom-left corner"
    aCanvas fillRectangle: (left@(barTop - 2) extent: 1@1) color: color.
    aCanvas fillRectangle: (left@(barTop - 1) extent: 2@1) color: color.
    aCanvas fillRectangle: (left@barTop extent: 3@1) color: color.

    aCanvas
        fillRectangle: ((left + 3)@barTop corner: (self right - 2)@(barTop + 1))
        color: highlightColor1.
    aCanvas
        fillRectangle: (left@(barTop + 1) corner: (self right - 1)@barBottom)
        color: color.
    aCanvas
        fillRectangle: ((self right - 1)@(barTop + 2) corner: self right@barBottom)
        color: shadowColor.

if you want it to change according to its status (reporter or not) then i suggest my code below:

Code:

drawBottomBarOn: aCanvas 

    | left barTop barBottom |
    (self isForever or: [self isReporter])
        ifTrue: [
            barBottom _ self bottom - 3.
            self drawSmoothBottomEdgeOn: aCanvas]
        ifFalse: [
            barBottom _ self bottom - 7.
            self drawBottomEdgeOn: aCanvas].

    barTop _ barBottom - (CBlockBracketThickness - 3).
    left _ self left + CBlockBracketThickness - 1.

    "fill in bottom-left corner"
    aCanvas fillRectangle: (left - 11@(barTop + 5) extent: 11@4) color: color.
    aCanvas fillRectangle: (left@(barTop - 2) extent: 1@1) color: color.
    aCanvas fillRectangle: (left@(barTop - 1) extent: 2@1) color: color.
    aCanvas fillRectangle: (left@barTop extent: 3@1) color: color.

    aCanvas
        fillRectangle: ((left + 3)@barTop corner: (self right - 2)@(barTop + 1))
        color: highlightColor1.
    aCanvas
        fillRectangle: (left@(barTop + 1) corner: (self right - 1)@barBottom)
        color: color.
    aCanvas
        fillRectangle: ((self right - 1)@(barTop + 2) corner: self right@barBottom)
        color: shadowColor.

hope this helps!!

Offline

 

#32 2010-11-21 14:32:13

zorket
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: New types of blocks wanted!

Bump!!!!!!!!  sad


Marzipan11 must learn to not spoil

Offline

 

#33 2010-11-22 19:33:38

zorket
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: New types of blocks wanted!

(screams at high-piched voice) BUMP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Marzipan11 must learn to not spoil

Offline

 

#34 2010-11-23 10:36:49

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: New types of blocks wanted!

Calm down zorket. (I seem to remember saying that before.)

You would need to create a new type of block to be a special form reporter. You then have to change ReporterBlockMorph's evaluate method to start a ScratchProcess for the block if it is a special form. You have to write code in the execution engine to return the value generated to the ReporterBlockMorph.

I'll put this in my mod, when it is released I give you permission to nick it all.


/* No comment */

Offline

 

#35 2010-11-23 15:52:02

zorket
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: New types of blocks wanted!

TheSuccessor wrote:

Calm down zorket. (I seem to remember saying that before.)

You did, so i posted http://scratch.mit.edu/forums/viewtopic.php?id=50916 sorry I'm not calmed down, but I'm getting really angry.

Last edited by zorket (2010-11-23 15:52:19)


Marzipan11 must learn to not spoil

Offline

 

#36 2010-11-23 16:48:40

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: New types of blocks wanted!

LS97 also gave you an answer, instead of bumping, how about you ask a new question related to what you want?

Offline

 

#37 2010-11-23 16:55:49

zorket
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: New types of blocks wanted!

Magnie wrote:

LS97 also gave you an answer, instead of bumping, how about you ask a new question related to what you want?

Because no one will ever answer me when I post.
Here, just look at this, PLEASE.

Last edited by zorket (2010-11-23 16:56:40)


Marzipan11 must learn to not spoil

Offline

 

#38 2010-11-23 17:04:53

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: New types of blocks wanted!

Yes, I read a lot of your posts. And that one I have already read and some people don't know how to do things, and some may not understand what you want, so just try to give as much info as possible, it'll work out.  smile

Offline

 

#39 2010-12-08 16:06:07

zorket
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: New types of blocks wanted!

TheSuccessor wrote:

You would need to create a new type of block to be a special form reporter. You then have to change ReporterBlockMorph's evaluate method to start a ScratchProcess for the block if it is a special form. You have to write code in the execution engine to return the value generated to the ReporterBlockMorph.
.

WHOAH! I don't really seem to understand, but I would like that post to stretch out easier. You may use the [code] and [/code] brackets.


Marzipan11 must learn to not spoil

Offline

 

#40 2010-12-22 18:23:47

zorket
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: New types of blocks wanted!

Ride, horsey! bump, bump, bump! Hey, slow down coward, there a log in fr... BUMP


Marzipan11 must learn to not spoil

Offline

 

#41 2011-04-16 16:06:52

zorket
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: New types of blocks wanted!

bump.


Marzipan11 must learn to not spoil

Offline

 

#42 2011-04-16 16:15:03

scratcher7_13
Scratcher
Registered: 2011-02-09
Posts: 1000+

Re: New types of blocks wanted!

I'm trying to figure this out too!


♫ 90% of teens can't do math. If you are one of the 40% of teens who can, copy and paste this into your signature. ♫♪
http://dl.dropbox.com/u/6273449/BlockLibraryTitle.pnghttp://i.imgur.com/mr9Hf.gif

Offline

 

#43 2011-04-16 18:48:55

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

Re: New types of blocks wanted!

zorket wrote:

4. HOW TO HACK BYOB:


Code:

Step 1. Right Click A Block (It Cannot Be A Custom Made Block.)


Step 2. Drag Some Of The Block Things Away Then Put Them Back EXACTLY How They Used To Be.


Step 3. Click The Little Save Button That Appeared.


Step 4. When It Asks For Your Initials, Type: Preferences enableProgrammerFacilities


Step 5. Highlight The Text And Press Alt+D


Step 6. Exit Out Of All Of That.


Step 7. Alt+Click The Scripting Area


Step 8. Press The Goldenish Circle


Step 9. Click Anywhere In The White Area That Appears.


Step 10. Press Open Then Press Browser

There is a much easier way than that, just edit elements, click class, then take a red report block (the squeak one) place a blue text insert block over into the report block and type in 

self

click save. Type in your initials. A syntax error should come up. Right click on the 'ScratchSpriteMorph class as yet classified Message' (the ScratchSpriteMorph may be ScriptableScratchMorph or ScratchStageMorph depending on what block you edited and where.) select 'browse full' and there you have it!

Last edited by Pecola1 (2011-04-16 18:49:56)


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

 

Board footer