Discuss Scratch

Awyzza
Scratcher
50 posts

Game loop faster than 30hz

A single frame forever loop, even with a timer like so
define loop
forever
wait ((1) / (60)) secs
nextTick
end
will freeze the project.
However with ‘run without screen refresh’ off, the loop can only run 30 times a second.
Is there any way to run a faster loop without crashing the project?

Last edited by Awyzza (June 10, 2021 02:27:02)

pro123465
Scratcher
100+ posts

Game loop faster than 30hz

you cannot add a forever loop in a run without screen refresh block, it will just crash scratch
pro123465
Scratcher
100+ posts

Game loop faster than 30hz

and you cannot run a faster loop than your fps, if your fps is 30, then it can only run 30 times in one second
dhuls
Scratcher
1000+ posts

Game loop faster than 30hz

1. Repeat blocks (repeat, repeat until, and forever) and wait blocks (wait () seconds, wait until, ask and wait, broadcast and wait, and switch backdrop and wait) should not be used in custom blocks because they cause immense lag. This is because they have a delay, and the custom block tries to run all of the code inside of it instantly, so it causes lag.
2. No. Scratch is locked to 30fps. Turbowarp, however, has a 60fps option.
pro123465
Scratcher
100+ posts

Game loop faster than 30hz

and you cannot run a faster loop than your fps, if your fps is 30, then it can only run 30 times in one second
dhuls
Scratcher
1000+ posts

Game loop faster than 30hz

pro123465 wrote:

and you cannot run a faster loop than your fps, if your fps is 30, then it can only run 30 times in one second
Did you mean to post the same thing twice?
hedgehog_blue
Scratcher
1000+ posts

Game loop faster than 30hz

The project cannot visibly update faster than 30 times per second, but you can perform many calculations without any screen refreshes to compute faster. If you want to a project to run as fast as possible by skipping screen refreshes, you can use turbo mode, but I believe the screen still only updates 30 times a second. This allows the project loop to process faster, but not actually refresh more often.

RokCoder
Scratcher
1000+ posts

Game loop faster than 30hz

Awyzza wrote:

A single frame forever loop, even with a timer like so
define loop
forever
wait ((1) / (60)) secs
nextTick
end
will freeze the project.
However with ‘run without screen refresh’ off, the loop can only run 30 times a second.
Is there any way to run a faster loop without crashing the project?
As mentioned, you can't use a forever (or a wait) within a non-refresh loop. Scratch is hard-coded to run at 30fps. If you want a different refresh rate then I'd recommend using TurboWarp (as also previous mentioned but it isn't restricted to just 30fps or 60fps - you can set it to any refresh rate you like).

dhuls wrote:

1. Repeat blocks (repeat, repeat until, and forever) and wait blocks (wait () seconds, wait until, ask and wait, broadcast and wait, and switch backdrop and wait) should not be used in custom blocks because they cause immense lag. This is because they have a delay, and the custom block tries to run all of the code inside of it instantly, so it causes lag.
2. No. Scratch is locked to 30fps. Turbowarp, however, has a 60fps option.
Mostly true but repeat and repeat until blocks are fine. In fact, they're a very good reason for using non-refresh blocks (as long as they are deterministically sure to not run forever).


Scratch dabbling for fun…

Powered by DjangoBB