(Redirected from Wait () Secs)
- "Wait" redirects here. For the other Control block with "wait" in its name, see Wait Until () (block).
Wait () Seconds | |
wait () seconds | |
Category | Control |
Type | Stack |
Introduced in | 14Feb04 |
The wait () seconds block is a control block and a stack block. It pauses its script for the specified amount of seconds — the wait can also be a decimal number.
This block is one of the most commonly used blocks; it is used whenever a sprite must wait for another action.
Prior to Scratch 3.0, this block was previously called "wait () secs."
Time Waited
This block will always wait at least 1/30 of a second, or one frame. It will always resume upon the closest 1/30 second increment.
Note: | If the project lags, this will not effect the time waited. Although this may be desirable, if you use other timing systems that do slow down when the project lags, when combined with this block, timing issues and discrepancies can arise. |
Example Uses
This block creates a pause whenever needed. As there are many situations where this is necessary, the block is used in many projects. Some common uses:
- Timers
forever wait (60) seconds change [minutes v] by (1)
- Animation delays
repeat (10) wait (0.05) seconds next costume
- Virtual simulations
wait (300) seconds broadcast (Morning v)
- Letting variables attain their proper value in the Java Player
when gf clicked set [var v] to [0] wait (0) seconds change [var v] by (1)
- In the Flash Player, allowing sprites to wait for a screen refresh so sprites can sense objects drawn by the pen.
stamp go to x: (-50) y: (0) wait (0) seconds repeat until <touching color [#000000]?>{ change x by (1) }::control loop
Workarounds
- Main article: List of Block Workarounds
This block can be replicated using any of the following scripts:
Using the Timer
reset timer wait until <not <(timer) < (value)>>
However, if the project resets the timer for other purposes, a different workaround should be used.
set [variable v] to (timer) wait until <not <((timer) - (variable)) < (wait duration)>>
The workaround uses the timer as a base instead of a player-made clock because the timer is more accurate; player-made clocks lag from the time it takes to change the clock variable.
Using Glide () Secs to X: () Y: ()
glide (wait duration) secs to x: (x position) y: (y position)
This workaround will muddle whatever movement the sprite is performing at the time, so it is best to keep the workaround to immobile sprites.
Using Say () for () Seconds or Think () for () Seconds
say [ ] for (wait duration) seconds
think [ ] for (wait duration) seconds
These two workarounds will ruin any thoughts or sayings that the sprite has at the time, so they should only be used on sprites that do not think or talk.
Using Rest for () Beats
rest for (((tempo) / (60)) * (wait duration)) beats
Using Play Sound () Until Done
Note: | This is assuming that the sound is exactly the wanted length. |
play sound (silent sound v) until done