Dear Squeakers,
I'm helping to develop MegaMod as some of you may know, and I'm trying to fix the honestly prehistoric Clone/Delete blocks. So I've added a C block which executes commands for another sprite, a bit like the existing 'make %m move %n steps' block.
However, while browsing the Scratch Execution Engine methods, I found no reference whatsoever to what sprite should execute the stack. I also tried setting a new variable called target and setting the CommandBlock's receiver to that variable, but it didn't work.
I know rubiks_cube_guy is fairly experienced in the area of Execution Engines; could anyone please help me in getting this solved? My code so far, in a method called doFor in ScratchProcess's special blocks, is this:
doFor
"Evaluate the current expression for a different sprite."
| block arguments argExp targetSprite |
block _ stackFrame expression.
arguments _ stackFrame arguments.
"Evaluate the arg if we haven't already."
arguments size = 0
ifTrue: [argExp _ block argumentAt: 1.
^self pushStackFrame: (ScratchStackFrame new expression: argExp)].
"We can pop this expression off the stack either way."
self popStackFrame.
"If the predicate was false, just return."
targetSprite _ arguments first.
(targetSprite isKindOf: ScriptableScratchMorph) ifFalse: [^ self].
"Evaluate the body of the C block for the given target"
specialTarget _ targetSprite.
self pushStackFrame: (ScratchStackFrame new expression: block firstBlockList).
specialTarget _ nil.Offline
I worked on that one for a while... never got it working, does that method work?
Offline
TheSuccessor wrote:
It's somewhere in this post.
Nope, it's not there (there's only a broadcast to sprite block).
And @Pecola:
My version doesn't work yet. It executes the stuff for the current sprite.
Offline
Yes it is...
rubiks_cube_guy238 wrote:
Put this into ScratchProcess:
Code:
doTellSpriteTo | t1 t2 t3 | t1 _ stackFrame expression. t2 _ stackFrame arguments. t2 size = 0 ifTrue: [t3 _ t1 argumentAt: 1. ^ self pushStackFrame: (ScratchStackFrame new expression: t3)]. self popStackFrame. t3 _ t1 fullCopy. t3 firstBlockList do: [:t4 | t4 receiver: (ScriptableScratchMorph new coerceSpriteArg: t2 first)]. self pushStackFrame: (ScratchStackFrame new expression: t3 firstBlockList)and go to SpriteArgMorph presentMenu and where it says
Code:
sel = #getAttribute:of:change it to say
Code:
(#(#getAttribute:of: #doTellSpriteTo ) includes: sel)
Offline
oh, oops
thanks!
Offline
Unfortunately, that block doesn't work too well. You can't use any C block inside it or it will return execution back to the calling sprite.
Offline
Next time, if this exact problem strikes again, just use "[Sprite] [Command]"!
Offline
rdococ wrote:
Next time, if this exact problem strikes again, just use "[Sprite] [Command]"!
I don't think you understand. This is for the end-user, not for me. I am perfectly aware that Squeak is an object-oriented language, and I know how to program, thanks a lot.
Offline
hey LS97, could you possibly make a [delete sprite [self]] block? you'd need to make a new uncoloredArgMorph for a dropdown that has 'self' and all the other sprites and not the stage.
Offline
jslomba wrote:
hey LS97, could you possibly make a [delete sprite [self]] block? you'd need to make a new uncoloredArgMorph for a dropdown that has 'self' and all the other sprites and not the stage.
Not needed. Delete sprite 'self' is already included, and dynamically deleting sprites won't work since the programmer will not know the name of the sprite.
Besides, you can always do
Last edited by LS97 (2011-06-29 10:59:20)
Offline
LS97 wrote:
jslomba wrote:
hey LS97, could you possibly make a [delete sprite [self]] block? you'd need to make a new uncoloredArgMorph for a dropdown that has 'self' and all the other sprites and not the stage.
Not needed. Delete sprite 'self' is already included, and dynamically deleting sprites won't work since the programmer will not know the name of the sprite.
Besides, you can always do
http://dl.dropbox.com/u/11532575/forums/MMdelete.gif
oh yeah. hey LS97, can you put the dialog blocks, the 'close megaMod' block, the 'clone/delete me' blocks, the 'import/record new sound' blocks, the 'import/draw/take pic for new costume' blocks, and the new block you're about to make to the 'special' category?
Offline
jslomba wrote:
LS97 wrote:
jslomba wrote:
hey LS97, could you possibly make a [delete sprite [self]] block? you'd need to make a new uncoloredArgMorph for a dropdown that has 'self' and all the other sprites and not the stage.
Not needed. Delete sprite 'self' is already included, and dynamically deleting sprites won't work since the programmer will not know the name of the sprite.
Besides, you can always do
http://dl.dropbox.com/u/11532575/forums/MMdelete.gifoh yeah. hey LS97, can you put the dialog blocks, the 'close megaMod' block, the 'clone/delete me' blocks, the 'import/record new sound' blocks, the 'import/draw/take pic for new costume' blocks, and the new block you're about to make to the 'special' category?
already done (except for the sound and image ones which I think are fine in their own categories)!
And I took the initiative of calling the category 'More' instead, is that ok?
Offline
LS97 wrote:
jslomba wrote:
LS97 wrote:
Not needed. Delete sprite 'self' is already included, and dynamically deleting sprites won't work since the programmer will not know the name of the sprite.
Besides, you can always do
http://dl.dropbox.com/u/11532575/forums/MMdelete.gifoh yeah. hey LS97, can you put the dialog blocks, the 'close megaMod' block, the 'clone/delete me' blocks, the 'import/record new sound' blocks, the 'import/draw/take pic for new costume' blocks, and the new block you're about to make to the 'special' category?
already done (except for the sound and image ones which I think are fine in their own categories)!
And I took the initiative of calling the category 'More' instead, is that ok?
yeah, that's fine. you added the right colors for the blocks, right?
Offline
jslomba wrote:
LS97 wrote:
jslomba wrote:
oh yeah. hey LS97, can you put the dialog blocks, the 'close megaMod' block, the 'clone/delete me' blocks, the 'import/record new sound' blocks, the 'import/draw/take pic for new costume' blocks, and the new block you're about to make to the 'special' category?already done (except for the sound and image ones which I think are fine in their own categories)!
And I took the initiative of calling the category 'More' instead, is that ok?
yeah, that's fine. you added the right colors for the blocks, right?
Ehm... *guilty face* I couldn't get them right...
The connections (i think you named it web) is purple, and the more is that red you saw above.
Offline
LS97 wrote:
jslomba wrote:
LS97 wrote:
already done (except for the sound and image ones which I think are fine in their own categories)!And I took the initiative of calling the category 'More' instead, is that ok?
yeah, that's fine. you added the right colors for the blocks, right?
Ehm... *guilty face* I couldn't get them right...
The connections (i think you named it web) is purple, and the more is that red you saw above.
okay, good enough.
Offline