Discuss Scratch

290Scratcher
Scratcher
1000+ posts

Timer goes faster than it should?

In a test, I made a variable that is supposed to run at the exact same speed as the timer.

whenclickedresettimerforeverwait0.1secschangetimerby0.1
The variable seems to be slower.

This can be proved by looking at this project.
Warriorbuilds3
Scratcher
100+ posts

Timer goes faster than it should?

This is because you put the wait block BEFORE the change variable block. Put the change variable block first, then the wait block, and it will work. This happens because you're putting a delay before it starts, thus putting it immediately behind.
Warriorbuilds3
Scratcher
100+ posts

Timer goes faster than it should?

marigoldkit wrote:

Warriorbuilds3 wrote:

This is because you put the wait block BEFORE the change variable block. Put the change variable block first, then the wait block, and it will work. This happens because you're putting a delay before it starts, thus putting it immediately behind.

that fixes it for a few seconds but once you get into double digits i can definitely still see a 1-2 second delay
Also, you might want to set the sprite's rotation style to don't rotate, so it doesn't lag as much. Less lag = Better performance
njb14
Scratcher
100+ posts

Timer goes faster than it should?

It's probably also because it takes time for the project to update the variable, wait 0.1 seconds and then go back to the start. It doesn't take much time, but eventually that's going to start to pile up and slow the variable down.
luke14444
Scratcher
11 posts

Timer goes faster than it should?

Same feature here.

When changed to:

forever
wait 1 sec
change by 1

timers run “at the same speed” with smaller error (compared to 0.1 case)

Seems that executing ( wait 1 sec; change by 1; repeat ) takes a bit more time than 1 second.

https://scratch.mit.edu/projects/181305176/
asivi
Scratcher
1000+ posts

Timer goes faster than it should?

https://scratch.mit.edu/projects/181264437/#editor You go there and see the reason.

Last edited by asivi (Oct. 21, 2017 06:35:07)

290Scratcher
Scratcher
1000+ posts

Timer goes faster than it should?

luke14444 wrote:

Same feature here.

When changed to:

forever
wait 1 sec
change by 1

timers run “at the same speed” with smaller error (compared to 0.1 case)

Seems that executing ( wait 1 sec; change by 1; repeat ) takes a bit more time than 1 second.

https://scratch.mit.edu/projects/181305176/
That actually does work.
luke14444
Scratcher
11 posts

Timer goes faster than it should?

Nope. Error is just smaller. Wait about 200 seconds and you will see the difference.
njb14
Scratcher
100+ posts

Timer goes faster than it should?

https://scratch.mit.edu/projects/181349337/
If you allow time for the script to be processed (around 0.008 seconds), it works fine

Last edited by njb14 (Oct. 21, 2017 14:21:49)

LordOfMuffins
Scratcher
100+ posts

Timer goes faster than it should?

In the
repeatforeverrepeatuntil
blocks there is a one-frame delay (about 0.03 seconds) after every loop in order to stop flash from crashing when somebody does something like this:
whenclickedforeversomethingwithoutthe"wait"blockafterit
If the delay wasn't there, the flash player would try to do “something without the ‘wait’ block after it” an infinite ammount of times a second, and we know that's not possible, so it would crash. You can disable the one-tick delay by doing this:
definetimerforeverchangetimerby0.1wait0.1secs
^^^^^^To get this to work correctly, in the options for the custom block you have to check the “run without screen refresh” checkbox. Problem solved!
asivi
Scratcher
1000+ posts

Timer goes faster than it should?

LordOfMuffins wrote:


definetimerforeverchangetimerby0.1wait0.1secs
^^^^^^To get this to work correctly, in the options for the custom block you have to check the “run without screen refresh” checkbox. Problem solved!

If you add any block with a wait in a no screen refresh custom block it will mess such script, and any other no screen refresh custom block in the project too, probably. Also that forever loop…
If you are not kidding us, please, just test it.

Last edited by asivi (Oct. 21, 2017 23:12:53)

plit234
Scratcher
93 posts

Timer goes faster than it should?

Warriorbuilds3 wrote:

This is because you put the wait block BEFORE the change variable block. Put the change variable block first, then the wait block, and it will work. This happens because you're putting a delay before it starts, thus putting it immediately behind.

Actually,it is going a bit more behind the timer,so that won't work.It's not the delay either.The only way to get the exact amount of the timer is this code:

whenclickedforeversettimertotimer

That makes it exactly be the same as the other timer.
290Scratcher
Scratcher
1000+ posts

Timer goes faster than it should?

plit234 wrote:

Warriorbuilds3 wrote:

This is because you put the wait block BEFORE the change variable block. Put the change variable block first, then the wait block, and it will work. This happens because you're putting a delay before it starts, thus putting it immediately behind.

Actually,it is going a bit more behind the timer,so that won't work.It's not the delay either.The only way to get the exact amount of the timer is this code:

whenclickedforeversettimertotimer

That makes it exactly be the same as the other timer.
The thing is theoretically the second script should make the variable run at the same speed as the in-built timer.
CGGSCC8
Scratcher
5 posts

Timer goes faster than it should?

290Scratcher wrote:

plit234 wrote:

Warriorbuilds3 wrote:

This is because you put the wait block BEFORE the change variable block. Put the change variable block first, then the wait block, and it will work. This happens because you're putting a delay before it starts, thus putting it immediately behind.

Actually,it is going a bit more behind the timer,so that won't work.It's not the delay either.The only way to get the exact amount of the timer is this code:

whenclickedforeversettimertotimer

That makes it exactly be the same as the other timer.
The thing is theoretically the second script should make the variable run at the same speed as the in-built timer.
that works
BosenChang
Scratcher
1000+ posts

Timer goes faster than it should?

No, it's supposed to be
whenclickedforeversettimertotimer
or
whenclickedsettimerto0foreverchangetimerby1
Yeetoburro1
Scratcher
1000+ posts

Timer goes faster than it should?

CGGSCC8 wrote:

this works:
whenclickedresettimerforeversettimertotimer
Please do not necropost, this topic is 3 years old
4096bits
Scratcher
1000+ posts

Timer goes faster than it should?

Yeetoburro1 wrote:

CGGSCC8 wrote:

this works:
whenclickedresettimerforeversettimertotimer
Please do not necropost, this topic is 3 years old
Okay, I'll report it to be closed.
i am not a moderator

Powered by DjangoBB