Search code examples
mit-scratch

Lag when exporting functionality into a block in Scratch


I'm new to scratch.

I have this code within a sprite, which works as expected without noticeable lags:

enter image description here

But, when I "export" the flickering into the 'flicker' block, it has a very nasty lag:

enter image description here

I created a special sprite in order to easily "feel" the lag, with this code:

enter image description here

This ball smoothly moves, until (every 5 seconds) there is the flickering effect and it stops for 1 second or so.

Can anyone give me a clue why it happens, and how to prevent it?

The project page is here.

Any assistance would be appreciated.


Solution

  • Let me start by pointing out that the problem does not occur when I launch your project. I tried it in 5 different web browsers on 3 different devices with 2 different operating systems, and every time, the ball just kept moving.

    However, I can make such an issue happen by enabling 'Run without screen refresh' in the 'flicker' block, as follows:

    • Right-click on the red 'define flicker' block.
    • From the context menu, select 'Edit'.
    • In the 'make a block' dialog, turn on checkbox 'Run without screen refresh', then click OK.

    I suspect 'Run without screen refresh' claims all processing power, effectively blocking any other (concurrent) scripts.

    My guess is, you already fixed the problem yourself by turning off 'Run without screen refresh'.

    In general, 'Run without screen refresh' is a great way to reduce lag in scripts where speed is essential. But never use it in a script with 'wait' or 'forever' blocks, or it will cause lag.