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

#1 2011-06-28 05:17:06

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

Scratch Process doFor C block

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:

Code:

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

 

#2 2011-06-28 12:05:58

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

Re: Scratch Process doFor C block

It's somewhere in this post.


/* No comment */

Offline

 

#3 2011-06-28 12:21:33

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

Re: Scratch Process doFor C block

I worked on that one for a while... never got it working, does that method work?


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

 

#4 2011-06-28 13:28:02

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

Re: Scratch Process doFor C block

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

 

#5 2011-06-28 13:59:23

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

Re: Scratch Process doFor C block

LS97 wrote:

TheSuccessor wrote:

It's somewhere in this post.

Nope, it's not there.

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)

/* No comment */

Offline

 

#6 2011-06-28 14:01:05

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

Re: Scratch Process doFor C block

oh, oops  tongue  thanks!

Offline

 

#7 2011-06-28 16:26:18

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

Re: Scratch Process doFor C block

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

 

#8 2011-06-29 02:31:18

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Offline

 

#9 2011-06-29 08:56:22

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

Re: Scratch Process doFor C block

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

 

#10 2011-06-29 09:01:31

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Scratch Process doFor C block

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.


the the the the the

Offline

 

#11 2011-06-29 10:41:48

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

Re: Scratch Process doFor C block

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

Last edited by LS97 (2011-06-29 10:59:20)

Offline

 

#12 2011-06-29 17:21:51

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Scratch Process doFor C block

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?


the the the the the

Offline

 

#13 2011-06-29 17:28:36

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

Re: Scratch Process doFor C block

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.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?

already done (except for the sound and image ones which I think are fine in their own categories)!  smile  And I took the initiative of calling the category 'More' instead, is that ok?

Offline

 

#14 2011-06-29 17:31:10

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Scratch Process doFor C block

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.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?

already done (except for the sound and image ones which I think are fine in their own categories)!  smile  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?


the the the the the

Offline

 

#15 2011-06-29 17:33:06

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

Re: Scratch Process doFor C block

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)!  smile  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

 

#16 2011-06-29 18:24:27

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Scratch Process doFor C block

LS97 wrote:

jslomba wrote:

LS97 wrote:


already done (except for the sound and image ones which I think are fine in their own categories)!  smile  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.


the the the the the

Offline

 

Board footer