To fit C blocks into strings:
Go to scratchBlocks > commandBlockMorph > all > add a 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)
Offline
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!
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: rcvrand 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
Last edited by LS97 (2010-11-04 08:24:00)
Offline
To get the bottom edge smooth, replace drawBottomBarOn: t1 in the drawing for CBlockMorph, with the following:
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:
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)
Offline
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!
Offline
here's the original 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:
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
(screams at high-piched voice) BUMP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Offline
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.
Offline
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)
Offline
LS97 also gave you an answer, instead of bumping, how about you ask a new question related to what you want?
Offline
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)
Offline
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.
Offline
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.
Offline
I'm trying to figure this out too!
Offline
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)
Offline