Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » This "wait" block workaround
- Cordongreen
-
Scratcher
1000+ posts
This "wait" block workaround
How does this workaround of the

wait () secsblock even work?

- deck26
-
Scratcher
1000+ posts
This "wait" block workaround
86400 seconds in a day so you're taking the time in seconds since 2000. So then the same calculation minus the recorded value gives the number of seconds that have passed since you recorded the value. When that is greater than the specified value you've waited that number of seconds.
- PotitChaton2
-
Scratcher
18 posts
This "wait" block workaround
Hey there.
This works using the “days since 2000” variable, also known as the epoch time. This variable constantly goes up and returns the current time elapsed, in days, since january 1st, 2000 at 00:00 UTC. The number has a decimal point, so it is very accurate. We can multiply it to get this number in hours (x24 because there are 24 hours in a day), minutes (x24 x60), or seconds (x24 x60 x60)! Knowing this, we can save the time in seconds at a specific moment, then later compare the time saved to the current time to know how much time has elapsed between the two moments. The code you showed does exactly that.
It first saves the current time in seconds by multiplying it by 86400, which is the same as 24*60*60, in a “time” variable
Then, it uses the “wait until …” block which constantly checks if the condition is true (the same as an empty “while not …” block)
The condition here first substracts the “time” variable to the current time, which will return the time elapsed or the difference between the two times. Then, it checks if the time elapsed is greater than the time you want to wait. If this is true, we know X seconds have passed since it saved the time.
Please tell me if you still have questions or if you didn’t understand something, I’ll be happy to help! Have a nice rest of your day.
This works using the “days since 2000” variable, also known as the epoch time. This variable constantly goes up and returns the current time elapsed, in days, since january 1st, 2000 at 00:00 UTC. The number has a decimal point, so it is very accurate. We can multiply it to get this number in hours (x24 because there are 24 hours in a day), minutes (x24 x60), or seconds (x24 x60 x60)! Knowing this, we can save the time in seconds at a specific moment, then later compare the time saved to the current time to know how much time has elapsed between the two moments. The code you showed does exactly that.
It first saves the current time in seconds by multiplying it by 86400, which is the same as 24*60*60, in a “time” variable
Then, it uses the “wait until …” block which constantly checks if the condition is true (the same as an empty “while not …” block)
The condition here first substracts the “time” variable to the current time, which will return the time elapsed or the difference between the two times. Then, it checks if the time elapsed is greater than the time you want to wait. If this is true, we know X seconds have passed since it saved the time.
Please tell me if you still have questions or if you didn’t understand something, I’ll be happy to help! Have a nice rest of your day.
- smisamul6
-
Scratcher
100+ posts
This "wait" block workaround
Hey there.All these explanations are confusing
This works using the “days since 2000” variable, also known as the epoch time. This variable constantly goes up and returns the current time elapsed, in days, since january 1st, 2000 at 00:00 UTC. The number has a decimal point, so it is very accurate. We can multiply it to get this number in hours (x24 because there are 24 hours in a day), minutes (x24 x60), or seconds (x24 x60 x60)! Knowing this, we can save the time in seconds at a specific moment, then later compare the time saved to the current time to know how much time has elapsed between the two moments. The code you showed does exactly that.
It first saves the current time in seconds by multiplying it by 86400, which is the same as 24*60*60, in a “time” variable
Then, it uses the “wait until …” block which constantly checks if the condition is true (the same as an empty “while not …” block)
The condition here first substracts the “time” variable to the current time, which will return the time elapsed or the difference between the two times. Then, it checks if the time elapsed is greater than the time you want to wait. If this is true, we know X seconds have passed since it saved the time.
Please tell me if you still have questions or if you didn’t understand something, I’ll be happy to help! Have a nice rest of your day.

- deck26
-
Scratcher
1000+ posts
This "wait" block workaround
Don't see why. All it's doing isHey there.All these explanations are confusing
This works using the “days since 2000” variable, also known as the epoch time. This variable constantly goes up and returns the current time elapsed, in days, since january 1st, 2000 at 00:00 UTC. The number has a decimal point, so it is very accurate. We can multiply it to get this number in hours (x24 because there are 24 hours in a day), minutes (x24 x60), or seconds (x24 x60 x60)! Knowing this, we can save the time in seconds at a specific moment, then later compare the time saved to the current time to know how much time has elapsed between the two moments. The code you showed does exactly that.
It first saves the current time in seconds by multiplying it by 86400, which is the same as 24*60*60, in a “time” variable
Then, it uses the “wait until …” block which constantly checks if the condition is true (the same as an empty “while not …” block)
The condition here first substracts the “time” variable to the current time, which will return the time elapsed or the difference between the two times. Then, it checks if the time elapsed is greater than the time you want to wait. If this is true, we know X seconds have passed since it saved the time.
Please tell me if you still have questions or if you didn’t understand something, I’ll be happy to help! Have a nice rest of your day.
get the current time in seconds
wait until the current time is x seconds more than the saved time
Note that current-time - saved-time > value is just the same as saying current-time > saved-time + value.
- -Qlec-
-
Scratcher
100+ posts
This "wait" block workaround
Here is the code, with comments:
define wait (sec) seconds
set [prev v] to ((days since 2000) * (86400)) // initial time
repeat until <((days since 2000)*(86400)) > ((sec) + (prev))> // delay until time is more than initial + wait time
change volume by (0)
end
Last edited by -Qlec- (Oct. 6, 2022 19:55:37)
- Discussion Forums
- » Help with Scripts
-
» This "wait" block workaround




