Discuss Scratch

helloyowuzzup
Scratcher
100+ posts

Repeat for X Seconds Block

So we have the ‘Repeat (x) times’ block and the ‘Repeat until’ block, but no ‘Repeat for (x) seconds’ block. Although you could potentially work around it 3 ways, none of them work very well.
Here's how I see it:

  • Have two scripts running at the same time, one of which stops everything and the other is repeating.

  • Do the math to figure out how many times to repeat so it will hide or do the next thing when you want it to.

  • Have a timer running for ‘repeat until’ so it repeats until the timer is at a certain number of seconds.


I will address each of these in order. There may be more complicated ways to make this work, but I've been using the site for 3 years on and off and I haven't figured them out, so I doubt a New Scratcher who just wanted to animate would be able to Sure, I don't use a ton of scripting, but I'm pretty familiar with it at this point :3

1. Run two scripts
Typically, you would use ‘Stop other scripts in this sprite’, ‘stop all’, or ‘hide’ if you wanted to use this method. But what if you don't want it to stop or hide? What if you just want it to switch and do something else? Then this just doesn't work. If you want your sprite to switch between costumes 2 and 3 for 10 seconds, then switch between 4 and 5 for 3 seconds, this option will not work.

2. Calculate how many times to repeat
Let's be honest: Even in a programming community, plenty of us are not really fans of math, to say the least. I, for one, hate it. But even if I do talk myself into calculating how many times I need to repeat it to last 15 seconds with .207 between each sprite, the Scratch lags. I've used this technique many times, and it just doesn't work from the lag that we're all used to.

3. Use a timer and ‘Repeat until’
First of all, timers are a pain in the back to mess with. But if you need to, you could try ‘Repeat until timer=30’. I think. That might not even work, I've never tried it. But with lag, again, it won't add up perfectly, I bet. And that might not even work XD Edit:

stickfiregames wrote:

-snip- you just need to use
<(timer) > (30)>
not
<(timer) = [30]>
-snip-


So that's why I think repeat ‘Repeat () seconds’ would be a great script to add. Please comment thoughts, suggestions, revisions- whatever's on your mind Thanks!

Support:
5 1/3

No support:
6

Last edited by helloyowuzzup (Nov. 19, 2014 23:39:49)

The_Grits
Scratcher
1000+ posts

Repeat for X Seconds Block

I really like this idea, and have needed it in some situations. Support!
stickfiregames
Scratcher
1000+ posts

Repeat for X Seconds Block

I don't see why the timer one is difficult, you just need to use
<(timer) > (30)>
not
<(timer) = [30]>

Still support though.
helloyowuzzup
Scratcher
100+ posts

Repeat for X Seconds Block

stickfiregames wrote:

I don't see why the timer one is difficult, you just need to use
<(timer) > (30)>
not
<(timer) = [30]>

Still support though.
Fair, but the timer sticks/lags sometimes, right? Good point though, and thanks for the support.
JudasR
Scratcher
71 posts

Repeat for X Seconds Block

helloyowuzzup wrote:

stickfiregames wrote:

I don't see why the timer one is difficult, you just need to use
<(timer) > (30)>
not
<(timer) = [30]>

Still support though.
Fair, but the timer sticks/lags sometimes, right? Good point though, and thanks for the support.
i have never seen the timer lag. the only thing close to that i've found is that if you switch to a different tab the scripts will slow down, but once you switch back they catch up to the timer, which has not stopped or lagged at all. the timer is more reliable than the "wait seconds" block and if you need anything with timing i fully recommend learning how to use the timer because it is the best.

the timer is my favorite block in case you couldn't tell
helloyowuzzup
Scratcher
100+ posts

Repeat for X Seconds Block

JudasR wrote:

helloyowuzzup wrote:

stickfiregames wrote:

I don't see why the timer one is difficult, you just need to use
<(timer) > (30)>
not
<(timer) = [30]>

Still support though.
Fair, but the timer sticks/lags sometimes, right? Good point though, and thanks for the support.
i have never seen the timer lag. the only thing close to that i've found is that if you switch to a different tab the scripts will slow down, but once you switch back they catch up to the timer, which has not stopped or lagged at all. the timer is more reliable than the "wait seconds" block and if you need anything with timing i fully recommend learning how to use the timer because it is the best.

the timer is my favorite block in case you couldn't tell
Whoa, no need to act that way. We don't need to be harsh It all depends on your computer, and in my case, the timer doesn't match up correctly most of the time- though I'm glad it does for yours! In this case, my suggestion would just be more of a shortcut (as many blocks are)
shoresbeep
Scratcher
1000+ posts

Repeat for X Seconds Block

\Like if then else
helloyowuzzup
Scratcher
100+ posts

Repeat for X Seconds Block

shoresbeep wrote:

\Like if then else
Precisely!
Sonickyle
Scratcher
1000+ posts

Repeat for X Seconds Block

set [time to repeat v] to ((timer) + [x]) //x being the time to repeat for.
repeat until <(timer) > (time to repeat)>
...
end
helloyowuzzup
Scratcher
100+ posts

Repeat for X Seconds Block

Sonickyle wrote:

set [time to repeat v] to ((timer) + [x]) //x being the time to repeat for.
repeat until <(timer) > (time to repeat)>
...
end
Why would you use ‘timer+x’? (I'm asking because I don't understand, not because I'm trying to be rude cx)
But even if that works, it's like we've covered before- just a much easier-to-use, probably more reliable shortcut ^u^
Sonickyle
Scratcher
1000+ posts

Repeat for X Seconds Block

helloyowuzzup wrote:

Sonickyle wrote:

set [time to repeat v] to ((timer) + [x]) //x being the time to repeat for.
repeat until <(timer) > (time to repeat)>
...
end
Why would you use ‘timer+x’? (I'm asking because I don't understand, not because I'm trying to be rude cx)
'timer+x' sets the variable to the current timer time plus the amount of time you want the repeat until to loop for. For example, if the timer is at 6.0 seconds, and I want to repeat for two seconds, the variable will set to 8, and so the repeat until will loop until the timer is greater than 8.
I've recently used this workaround in my Project Diva game for the note timing.

I'm not sure if I should support something that has a workaround as simple as above though.
QuoStrike
Scratcher
32 posts

Repeat for X Seconds Block

I support
RPFluffy
Scratcher
1000+ posts

Repeat for X Seconds Block

I would like to point out, the timer part is easy, use this:

repeat until <<(timer) = [30 ]> or <(timer) > [30 ]>

end

No support. It's been suggested many times but I will never support as the workarounds are too easy.

Last edited by RPFluffy (Nov. 16, 2014 17:07:37)

AonymousGuy
Scratcher
1000+ posts

Repeat for X Seconds Block

Workaround:
set [offset v] to (timer) //So that we don't have to reset the timer
repeat until <((timer) - (offset)) > (value :: grey)>
do stuff :: grey
end

And if the timer sometimes gets off on timing because of lag, so will this block.

No support.

Last edited by AonymousGuy (Nov. 16, 2014 17:18:35)

shoresbeep
Scratcher
1000+ posts

Repeat for X Seconds Block

I support (not sure if I already did…)
Firedrake969
Scratcher
1000+ posts

Repeat for X Seconds Block

No support for workarounds above, and the timer is more accurate than any other time block in Scratch AFAIK.
Sonickyle
Scratcher
1000+ posts

Repeat for X Seconds Block

Firedrake969 wrote:

and the timer is more accurate than any other time block in Scratch AFAIK.
Yeah. I think that's because it works in real time instead of the wait block's framerate time.
beaglecub
Scratcher
100+ posts

Repeat for X Seconds Block

Supportiee morty. XD

This block would be easy for new scratchers, it should be added.
helloyowuzzup
Scratcher
100+ posts

Repeat for X Seconds Block

beaglecub wrote:

Supportiee morty. XD

This block would be easy for new scratchers, it should be added.
My point exactly
peppermintpatty5
Scratcher
1000+ posts

Repeat for X Seconds Block

No support, especially for number 2, since
repeat (10)
end
is already a huge convinience that most new Scratchers can't fully appreciate. In Java, you would have to make your own counter, like this:
set [counter v] to [0]
repeat until <(counter) > [9]>
set [counter v] to ((counter) + (1))
end
Sorry, can't say that those are my favorite ideas.

Last edited by peppermintpatty5 (Nov. 17, 2014 02:37:33)

Powered by DjangoBB