Well, OK. So file in this code:
'From MIT Squeak 0.9.4 (June 1, 2003) [No updates present.] on 20 September 2010 at 3:32:28 pm'!
EventHatMorph subclass: #ProcedureHatBlockMorph
instanceVariableNames: 'argMorphs commandSpec addInputVarMorph removeInputVarMorph '
classVariableNames: ''
poolDictionaries: ''
category: 'Scratch-Blocks'!
!ProcedureHatBlockMorph methodsFor: 'as yet unclassified'!
addInputVar
self commandSpec: commandSpec , '%s'.
self addMorphBack: removeInputVarMorph.
self addMorphBack: addInputVarMorph.
self replaceArgMorph: (self argumentAt: argMorphs size)
by: (VariableBlockMorph new commandSpec: ('input' , argMorphs size asString) localized;
isSpecialForm: true).
self fixBlockLayout! !
!ProcedureHatBlockMorph methodsFor: 'as yet unclassified'!
addLabel
| t1 t2 t3 t4 t5 |
commandSpec ifNil: [^ self].
t5 _ self nextBlock.
self removeAllMorphsIn: (self submorphs reject: [:t6 | t6 = t5]).
t1 _ CommandBlockMorph parseCommandSpec: commandSpec.
t2 _ t1 select: [:t7 | CommandBlockMorph isArgSpec: t7].
[argMorphs size > t2 size]
whileTrue:
[t4 _ argMorphs last.
argMorphs remove: t4.
(t4 isKindOf: BlockMorph)
ifTrue: [t4 openInWorld]].
[argMorphs size < t2 size]
whileTrue: [argMorphs addLast: (self argMorphFor: (t2 at: argMorphs size + 1))].
t3 _ 1.
t1 do:
[:t7 |
(CommandBlockMorph isArgSpec: t7)
ifTrue:
[t4 _ argMorphs at: t3.
t3 _ t3 + 1]
ifFalse: [t4 _ self labelMorphFor: t7].
self addMorphBack: t4].
self isReporter
ifTrue:
[t4 _ submorphs first.
(t4 isKindOf: ChoiceArgMorph)
| (t4 isKindOf: SpriteArgMorph) ifTrue: [self addMorphFront: (Morph new color: Color transparent;
extent: 2 @ 5)].
t4 _ submorphs last.
(t4 isKindOf: ChoiceArgMorph)
| (t4 isKindOf: SpriteArgMorph) ifTrue: [self addMorphBack: (Morph new color: Color transparent;
extent: 2 @ 5)]]! !
!ProcedureHatBlockMorph methodsFor: 'as yet unclassified'!
argMorphFor: t1
^ ExpressionArgMorph new stringExpression: ''! !
!ProcedureHatBlockMorph methodsFor: 'as yet unclassified'!
argumentAt: t1
^ argMorphs at: t1! !
!ProcedureHatBlockMorph methodsFor: 'as yet unclassified'!
commandSpec: t1
commandSpec _ t1.
self addLabel! !
!ProcedureHatBlockMorph methodsFor: 'as yet unclassified'!
fixBlockLayout
| t1 |
super fixBlockLayout.
t1 _ self position + (10 @ 18).
self addMorphBack: addInputVarMorph.
argMorphs size > 1 ifTrue: [self addMorphBack: removeInputVarMorph].
submorphs do: [:t2 | (t2 isKindOf: ExpressionArgMorph)
| (t2 isKindOf: StringMorph) | (t2 isKindOf: VariableBlockMorph)
ifTrue:
[t2 position: t1.
t1 _ t2 topRight + (3 @ 0)]].
removeInputVarMorph position: t1.
t1 _ removeInputVarMorph topRight + (14 @ 0).
addInputVarMorph position: t1 + (-20 @ -1).
t1 _ addInputVarMorph topRight + (3 @ 0).
self width: t1 x - self position x! !
!ProcedureHatBlockMorph methodsFor: 'as yet unclassified'!
initialize
super initialize.
argMorphs _ OrderedCollection new.
self commandSpec: 'procedure %s with inputs'.
addInputVarMorph _ ImageMorph new form: ((ScratchFrameMorph skinAt: #arrowOpenComment)
rotateBy: -90).
removeInputVarMorph _ ImageMorph new form: ((ScratchFrameMorph skinAt: #arrowOpenComment)
rotateBy: 90).
self addMorphBack: addInputVarMorph.
self fixBlockLayout! !
!ProcedureHatBlockMorph methodsFor: 'as yet unclassified'!
labelMorphFor: t1
| t2 |
t2 _ t1.
commandSpec isUnicode ifTrue: [t2 _ UTF8 withAll: t2].
^ (StringMorph contents: t2 font: (ScratchFrameMorph getFont: #Label))
color: Color white! !
!ProcedureHatBlockMorph methodsFor: 'as yet unclassified'!
mouseDown: t1
t1 hand newKeyboardFocus: nil.
t1 anyButtonPressed
ifTrue:
[(addInputVarMorph containsPoint: t1 cursorPoint)
ifTrue: [^ self addInputVar].
(removeInputVarMorph containsPoint: t1 cursorPoint)
ifTrue: [^ self removeInputVar]].
^ super mouseDown: t1! !
!ProcedureHatBlockMorph methodsFor: 'as yet unclassified'!
removeInputVar
self commandSpec: (commandSpec allButLast: 2).
argMorphs size = 1 ifTrue: [removeInputVarMorph delete].
self addMorphBack: addInputVarMorph.
self fixBlockLayout! !
!ProcedureHatBlockMorph methodsFor: 'as yet unclassified'!
replaceArgMorph: t1 by: t2
argMorphs _ argMorphs
collect: [:t3 | t3 == t1
ifTrue: [t2]
ifFalse: [t3]].
self replaceSubmorph: t1 by: t2.
self layoutChanged! !
!ScriptableScratchMorph methodsFor: 'blocks'!
hatBlockType: t1
| t2 t3 |
'E' = t1
ifTrue:
[t3 _ ''.
(t2 _ self ownerThatIsA: ScratchStageMorph) ifNotNil: [t3 _ t2 defaultEventName].
^ EventHatMorph new scriptOwner: self;
eventName: t3].
'K' = t1 ifTrue: [^ KeyEventHatMorph new scriptOwner: self].
'M' = t1 ifTrue: [^ MouseClickEventHatMorph new scriptOwner: self].
'S' = t1 ifTrue: [^ EventHatMorph new forStartEvent scriptOwner: self].
'W' = t1 ifTrue: [^ WhenHatBlockMorph new scriptOwner: self].
'P' = t1 ifTrue: [^ ProcedureHatBlockMorph new scriptOwner: self]! !
!ScriptableScratchMorph methodsFor: 'blocks'!
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 #P ) includes: t4)
ifTrue: [^ (self hatBlockType: t4)
color: t2].
(t4 includes: $c)
ifTrue: [t5 = #doIfElse | (t3 = 'switch')
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: $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! !and add this block
('' #P #-)OK. Now drag out the new block into the scripting area, and click on the little arrow. The text input box disapears from the other block still in the blocks (not scripting, but blocks) tab! What's going on here!?
Yes, for some wierd reason, you can drag out the input vars in my mod. IDK why you can't do that when you fileIn the code.
EDIT: Fixed! (Moderators, please don't close this topic).
This block should be pretty self-explanatory. It's sort of a cross between Panther and BYOB. But here's the catch: The blocks are all compiled into code and then run! This means that repeat blocks don't cause lag!
Last edited by rubiks_cube_guy238 (2010-09-22 17:56:14)
Offline
What's it do, or look like? (I can't be bother to get it
)
Offline
nXIII wrote:
I think you need to modify "self duplicate" to create copies of the arguments instead of pointers to the same argument in the old block.
Wait, what!? Where!? How!?
Offline
rubiks_cube_guy238 wrote:
nXIII wrote:
I think you need to modify "self duplicate" to create copies of the arguments instead of pointers to the same argument in the old block.
Wait, what!? Where!? How!?
I think when it calls duplicate the argument morph pointers are copied, rather than made to point at their respective copies. You can modify this by overriding the #duplicate method (I think
)
Offline
nXIII wrote:
rubiks_cube_guy238 wrote:
nXIII wrote:
I think you need to modify "self duplicate" to create copies of the arguments instead of pointers to the same argument in the old block.
Wait, what!? Where!? How!?
I think when it calls duplicate the argument morph pointers are copied, rather than made to point at their respective copies. You can modify this by overriding the #duplicate method (I think
)
No, you don't get it. The problem is that when you add an argument, the ExpressionArgMorph is 'stollen' from the original block still in the palette.
Offline
WHOA the counter in my signature just went up from 89 to 123.
Offline
rubiks_cube_guy238 wrote:
nXIII wrote:
rubiks_cube_guy238 wrote:
Wait, what!? Where!? How!?I think when it calls duplicate the argument morph pointers are copied, rather than made to point at their respective copies. You can modify this by overriding the #duplicate method (I think
)
No, you don't get it. The problem is that when you add an argument, the ExpressionArgMorph is 'stollen' from the original block still in the palette.
No, I do get it.
When you DUPLICATE IT (drag it from the partsBin to the scripting area, this uses DUPLICATION) it copies the pointer to the original expressionArgMorph, and so it removes that when it updates the commandSpec:
Offline
nXIII wrote:
rubiks_cube_guy238 wrote:
nXIII wrote:
I think when it calls duplicate the argument morph pointers are copied, rather than made to point at their respective copies. You can modify this by overriding the #duplicate method (I think)
No, you don't get it. The problem is that when you add an argument, the ExpressionArgMorph is 'stollen' from the original block still in the palette.
No, I do get it.
![]()
When you DUPLICATE IT (drag it from the partsBin to the scripting area, this uses DUPLICATION) it copies the pointer to the original expressionArgMorph, and so it removes that when it updates the commandSpec:
OK, now I think I have the general idea of how to fix it. However, I think I need to override the #fullCopy method, not the #duplicate method. #duplicate is only when you select 'duplicate' from the right-button menu.
Offline
rubiks_cube_guy238 wrote:
nXIII wrote:
rubiks_cube_guy238 wrote:
No, you don't get it. The problem is that when you add an argument, the ExpressionArgMorph is 'stollen' from the original block still in the palette.No, I do get it.
![]()
When you DUPLICATE IT (drag it from the partsBin to the scripting area, this uses DUPLICATION) it copies the pointer to the original expressionArgMorph, and so it removes that when it updates the commandSpec:OK, now I think I have the general idea of how to fix it. However, I think I need to override the #fullCopy method, not the #duplicate method. #duplicate is only when you select 'duplicate' from the right-button menu.
Oh, sorry, yes, that's what I meant
Offline
nXIII wrote:
rubiks_cube_guy238 wrote:
nXIII wrote:
No, I do get it.
![]()
When you DUPLICATE IT (drag it from the partsBin to the scripting area, this uses DUPLICATION) it copies the pointer to the original expressionArgMorph, and so it removes that when it updates the commandSpec:OK, now I think I have the general idea of how to fix it. However, I think I need to override the #fullCopy method, not the #duplicate method. #duplicate is only when you select 'duplicate' from the right-button menu.
Oh, sorry, yes, that's what I meant
![]()
It almost works. I did this (in ProcedureHatBlockMorph)
Code:
fullCopy
^ self shallowCopy
but, as I say, killing one bug only swarms more bugs around it.
Offline
nXIII wrote:
Try
Code:
fullCopy
| copy |
copy _ super fullCopy.
copy argMorphs at: 1 put: (copy findA: ExpressionArgMorph).
^ copy
OMG THANKYOUTHANKYOUTHANKYOU you have NO idea how much this glitch has annoyed me.
Offline
rubiks_cube_guy238 wrote:
OMG THANKYOUTHANKYOUTHANKYOU you have NO idea how much this glitch has annoyed me.
I know, I hate it when that happens to me!
Jens and I (but mostly Jens
) spent so long trying to debug a glitch with lists and it was all because the lists' = operator was overridden!
Last edited by nXIII (2010-09-22 15:24:34)
Offline