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

#1 2012-12-19 09:30:01

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

Squeak execution engine help

Hello,
I was attempting a "run without screen refresh" C block like Scratch 2.0 used to have.
It basically sets turbo mode, then runs the blocks, then unsets turbo.

It works, but when the following script is attempted it stays in turbo mode.
http://modshare.org/imgsrv/view/3/turbobingo1.gif

However, when I add a wait block, it registers the un-turbo.
http://modshare.org/imgsrv/view/3/turbobingo2.gif

What's the problem with my code?

doWithoutRefresh

    | block frame args |

    block _ stackFrame expression.
    args _ stackFrame arguments.

    "Check whether this time I'm only reverting to normal screen refresh"
    args size > 1 ifTrue: [
        args first = true ifTrue: [
            BlockHighlightMSecs _ args second.
            self popStackFrame.
            ^ self pushStackFrame: (ScratchStackFrame new shouldYield: true).
        ]
    ].

    "Pop this instruction from the stack."
    self popStackFrameNoUnhightlight.

    "add the following to the stack so they will be evaluated in reverse order:"

    "3. call this function again when the yeilds are terminated"
    frame _ ScratchStackFrame new
                expression:        block;
                addArgument:    true;
                addArgument:    BlockHighlightMSecs.
    self pushStackFrame: frame.

    "2. yield"
    self pushStackFrame: (ScratchStackFrame new shouldYield: true).

    "1. evaluate the body of the C block"
    self pushStackFrame: (ScratchStackFrame new expression: block firstBlockList).

    "enter turbo mode now and let the engine run the first block"
    BlockHighlightMSecs _ 0.

Last edited by LS97 (2012-12-19 10:35:37)

Offline

 

#2 2012-12-19 10:00:30

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

Re: Squeak execution engine help

I haven't tested this, but perhaps after you've popped the block off the stack the second time after resetting BlockHighlightMSecs, add a yield frame? Also, you may want to consider keeping track of whether the user was already in turbo mode.


/* No comment */

Offline

 

#3 2012-12-20 06:41:34

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

Re: Squeak execution engine help

TheSuccessor wrote:

I haven't tested this, but perhaps after you've popped the block off the stack the second time after resetting BlockHighlightMSecs, add a yield frame? Also, you may want to consider keeping track of whether the user was already in turbo mode.

Adding a yield didn't work, but it's still probably a good idea to keep it there  smile
And now it remembers the previous turbo state as you suggested.

Offline

 

#4 2012-12-20 08:06:15

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Squeak execution engine help

The way stepping works is that if turbo mode is activated, the stage will unconditionally step as many frames as possible in a fixed time period. What's happening with your block is that it's completing so fast that there is plenty of time left over for the stage to finish the rest of the script—it doesn't check whether turbo mode has been deactivated while stepping.

I would recommend that you just set some flag on the evaluator when you encounter a <do without screen refresh> block, and remove it after evaluating. The flag would cause the "yield" method to be ignored, so the evaluator would continue until it hit the end of the <do without screen refresh> block and yield after it (if that's the behavior you want). Make sure to check for nesting, though.

EDIT: Also, why are your inputs weirdly-colored?

Last edited by nXIII (2012-12-20 08:08:19)


nXIII

Offline

 

#5 2012-12-20 10:59:24

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Squeak execution engine help

nXIII wrote:

The way stepping works is that if turbo mode is activated, the stage will unconditionally step as many frames as possible in a fixed time period. What's happening with your block is that it's completing so fast that there is plenty of time left over for the stage to finish the rest of the script—it doesn't check whether turbo mode has been deactivated while stepping.

I would recommend that you just set some flag on the evaluator when you encounter a <do without screen refresh> block, and remove it after evaluating. The flag would cause the "yield" method to be ignored, so the evaluator would continue until it hit the end of the <do without screen refresh> block and yield after it (if that's the behavior you want). Make sure to check for nesting, though.

EDIT: Also, why are your inputs weirdly-colored?

I suppose the inputs are weirdly coloured because when I save a picture of blocks to upload to github, it usually does the same kind of thing. I just use an imaging editing software to remove that effect.


I'm back.
Maybe.

Offline

 

#6 2012-12-20 12:15:37

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Squeak execution engine help

DigiTechs wrote:

I suppose the inputs are weirdly coloured because when I save a picture of blocks to upload to github, it usually does the same kind of thing. I just use an imaging editing software to remove that effect.

…You didn't save those pictures, and they're not on Github…

It's obviously a change to the drawing method; I was just wondering about the rationale. It makes them harder to read.

Last edited by nXIII (2012-12-20 12:16:09)


nXIII

Offline

 

#7 2012-12-20 12:26:23

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

Re: Squeak execution engine help

nXIII wrote:

The way stepping works is that if turbo mode is activated, the stage will unconditionally step as many frames as possible in a fixed time period. What's happening with your block is that it's completing so fast that there is plenty of time left over for the stage to finish the rest of the script—it doesn't check whether turbo mode has been deactivated while stepping.

I would recommend that you just set some flag on the evaluator when you encounter a <do without screen refresh> block, and remove it after evaluating. The flag would cause the "yield" method to be ignored, so the evaluator would continue until it hit the end of the <do without screen refresh> block and yield after it (if that's the behavior you want). Make sure to check for nesting, though.

EDIT: Also, why are your inputs weirdly-colored?

Ah, that makes a lot more sense. Thanks!

As for the coloured inputs, I think they look cooler and not too much harder to read. Bingo 1.3 already has them like that. Originally I only changed the reporters to be gradient like that, but then I though it would be more consistent if I matched their holders.

Offline

 

Board footer