Discuss Scratch

lizardvenom64
Scratcher
5 posts

How To Reduce Lag?

I have a project where there is a lot of code, and sometimes some parts of the code lag behind others. How do I stop this?
KokichiUchiha
Scratcher
1000+ posts

How To Reduce Lag?

Using Custom Blocks usually reduce lag while there are big numbers of actions in one script. That's why Custom Blocks exist, they shorten scripts to reduce lag.
TheTotalKid777
Scratcher
14 posts

How To Reduce Lag?

lizardvenom64 wrote:

I have a project where there is a lot of code, and sometimes some parts of the code lag behind others. How do I stop this?

3 things:

1. Don't use too much forever loops like less than 5
2. Use custom blocks in big scripts

define 

3. It might look to the editor the project is laggy but to the viewer is not.

If you do these things, the project will probably not lag.
lizardvenom64
Scratcher
5 posts

How To Reduce Lag?


TheTotalKid777 wrote:

lizardvenom64 wrote:

I have a project where there is a lot of code, and sometimes some parts of the code lag behind others. How do I stop this?

3 things:

1. Don't use too much forever loops like less than 5
2. Use custom blocks in big scripts

define 

3. It might look to the editor the project is laggy but to the viewer is not.

If you do these things, the project will probably not lag.
Ok, I will try these. Thanks for the help!
aceyp9000
Scratcher
100+ posts

How To Reduce Lag?

If you are using custom blocks and it still lags, try checking the “run without screen refresh” box inside the custom block.
Windowz10
Scratcher
8 posts

How To Reduce Lag?

this method increases your FPS by 3 - 6

firstly find you main forever loop that is doing every thing (P.S. it cant be in a When i recieve block)

here is my example script

when green flag clicked
forever
broadcast [do something v]
turn cw (7) degrees
end


what you have to do is make 2 seperate scripts like this

when green flag clicked
forever
change [Counter v] by (1)
end

when green flag clicked
forever
wait (1) secs
set [Fps v] to (Counter)
set [Counter v] to [0]
end

now find your main script and surround the inside blocks with a repeat fps and at the end of the repeat loop put a wait 1/Fps block

when green flag clicked
forever
repeat (Fps)
broadcast [do something v]
turn cw (7) degrees
wait ((1) / (Fps)) secs
end
end

in a normal script, scratch tries to do everything quickly for the next frame causing stress and lag, but with the method i just said, it will take its time and when the fps is low it will understand that its laggy and it will be careful

Last edited by Windowz10 (April 8, 2022 06:59:03)

BladeJC1
Scratcher
1 post

How To Reduce Lag?

if you use the stop this script block does it make it less laggy too? like if you use a forever block and then after a certain action it stops the forever block. I'm wondering if that also helps.
jonathasgmc32
Scratcher
30 posts

How To Reduce Lag?

Something simple that also helps is keeping the first sprite without any code or costume. This helps a lot for anyone just running their project.
cs2722201
Scratcher
100+ posts

How To Reduce Lag?

You could have one forever loop sending ticks in broadcast messages. When the tick broadcast is received the project does what it needs to. Works like a forever loop but less laggy. Also better for coding as you can slow it down or speed it up.

Powered by DjangoBB