Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Make loop always run at 30 times per second, even in turbo mode
- helloworldbyeworld
- Scratcher
1000+ posts
Make loop always run at 30 times per second, even in turbo mode
Hello,
I'm making a platformer and I would like to make it so that even when you enable turbo mode, the main loop won't run too fast (still at 30 times per second). I have tried adding a wait 1/30 second block at the end of the loop, but that makes the framerate too slow when turbo mode is not enabled. I have considered doing a lengthy turbo mode check each time and deciding if it should wait, but I think that would lag up the project when it's not enabled. Is there another way for this? Any help would be appriciated.
Here's the link to the project (it's shared): https://scratch.mit.edu/projects/601066043/
Thanks!
I'm making a platformer and I would like to make it so that even when you enable turbo mode, the main loop won't run too fast (still at 30 times per second). I have tried adding a wait 1/30 second block at the end of the loop, but that makes the framerate too slow when turbo mode is not enabled. I have considered doing a lengthy turbo mode check each time and deciding if it should wait, but I think that would lag up the project when it's not enabled. Is there another way for this? Any help would be appriciated.
Here's the link to the project (it's shared): https://scratch.mit.edu/projects/601066043/
Thanks!
Helloworldbyeworld | 1200+ posts
Have a great day
- helloworldbyeworld
- Scratcher
1000+ posts
Make loop always run at 30 times per second, even in turbo mode
Bump
Helloworldbyeworld | 1200+ posts
Have a great day
- qloakonscratch
- Scratcher
1000+ posts
Make loop always run at 30 times per second, even in turbo mode
when green flag clicked
broadcast [check v]
when I receive [check v]
reset timer
repeat until <(timer) = [1]>
change [checker v] by (1)
end
if <<(checker) = [100]> or <(checker) > [100]>> then
...
end
broadcast [check v]
It won't lag.
Now Showing: CCRP V
https://scratch.mit.edu/studios/33864948/
Coding on Scratch since 2013
Foruming since 2016
In the Forum Helpers since 2022
- helloworldbyeworld
- Scratcher
1000+ posts
Make loop always run at 30 times per second, even in turbo mode
Thanks for the script! When I have time, I will try it.when green flag clicked
broadcast [check v]
when I receive [check v]
reset timer
repeat until <(timer) = [1]>
change [checker v] by (1)
end
if <<(checker) = [100]> or <(checker) > [100]>> then
...
end
broadcast [check v]
It won't lag.
I only have one question: Does the … placeholder run when turbo mode is not enabled, or the other way around?
Helloworldbyeworld | 1200+ posts
Have a great day
- qloakonscratch
- Scratcher
1000+ posts
Make loop always run at 30 times per second, even in turbo mode
it should run only when turbo mode is activated, but you could add a script to make it 30 frames while turbo mode is activated. It's in a loop to make sure it keeps checking for Turbo mode, but I don't like using forever block for this since its more likely to lag.Thanks for the script! When I have time, I will try it.when green flag clicked
broadcast [check v]
when I receive [check v]
reset timer
repeat until <(timer) = [1]>
change [checker v] by (1)
end
if <<(checker) = [100]> or <(checker) > [100]>> then
...
end
broadcast [check v]
It won't lag.
I only have one question: Does the … placeholder run when turbo mode is not enabled, or the other way around?
Also, remember to set the checker to 0 every time the thing is broadcasted.
Now Showing: CCRP V
https://scratch.mit.edu/studios/33864948/
Coding on Scratch since 2013
Foruming since 2016
In the Forum Helpers since 2022
- helloworldbyeworld
- Scratcher
1000+ posts
Make loop always run at 30 times per second, even in turbo mode
I actually have one more question: do I need to keep the check broadcast as a broadcast and not do it as a custom block?it should run only when turbo mode is activated, but you could add a script to make it 30 frames while turbo mode is activated. It's in a loop to make sure it keeps checking for Turbo mode, but I don't like using forever block for this since its more likely to lag.(Snipped scripts)Thanks for the script! When I have time, I will try it.
It won't lag.
I only have one question: Does the … placeholder run when turbo mode is not enabled, or the other way around?
Also, remember to set the checker to 0 every time the thing is broadcasted.
Helloworldbyeworld | 1200+ posts
Have a great day
- qloakonscratch
- Scratcher
1000+ posts
Make loop always run at 30 times per second, even in turbo mode
Yes, I would recommend that, though you could do it as a custom block.I actually have one more question: do I need to keep the check broadcast as a broadcast and not do it as a custom block?it should run only when turbo mode is activated, but you could add a script to make it 30 frames while turbo mode is activated. It's in a loop to make sure it keeps checking for Turbo mode, but I don't like using forever block for this since its more likely to lag.(Snipped scripts)Thanks for the script! When I have time, I will try it.
It won't lag.
I only have one question: Does the … placeholder run when turbo mode is not enabled, or the other way around?
Also, remember to set the checker to 0 every time the thing is broadcasted.
define Check for Turbo Mode
reset timer
set [checker v] to [0]
repeat until <(timer) = [1]>
change [checker v] by (1)
end
if <<(checker) = [100]> or <(checker) > [100]>> then
...
end
Check for Turbo Mode
Now Showing: CCRP V
https://scratch.mit.edu/studios/33864948/
Coding on Scratch since 2013
Foruming since 2016
In the Forum Helpers since 2022
- helloworldbyeworld
- Scratcher
1000+ posts
Make loop always run at 30 times per second, even in turbo mode
Ok! That is all I need. I will try it soon.Yes, I would recommend that, though you could do it as a custom block.I actually have one more question: do I need to keep the check broadcast as a broadcast and not do it as a custom block?it should run only when turbo mode is activated, but you could add a script to make it 30 frames while turbo mode is activated. It's in a loop to make sure it keeps checking for Turbo mode, but I don't like using forever block for this since its more likely to lag.(Snipped scripts)Thanks for the script! When I have time, I will try it.
It won't lag.
I only have one question: Does the … placeholder run when turbo mode is not enabled, or the other way around?
Also, remember to set the checker to 0 every time the thing is broadcasted.define Check for Turbo Mode
reset timer
set [checker v] to [0]
repeat until <(timer) = [1]>
change [checker v] by (1)
end
if <<(checker) = [100]> or <(checker) > [100]>> then
...
end
Check for Turbo Mode
Last edited by helloworldbyeworld (Dec. 7, 2021 02:11:02)
Helloworldbyeworld | 1200+ posts
Have a great day
- Discussion Forums
- » Help with Scripts
- » Make loop always run at 30 times per second, even in turbo mode