Discuss Scratch

Froggy_Man1
Scratcher
10 posts

Repeat help

I want to code something that repeats a set of costumes. In my case I want to repeat 53 through 56 until a button is let go (so it can switch to another costume. This is what I have:
when green flag clicked
forever
if <key [a] pressed?> then
switch costume to [52]
repeat until <not <key [a] pressed?>>
repeat <(costume #) = [56]>
wait (0.02) secs
next costume

end

end
switch costume to [57]
end
end

Last edited by Froggy_Man1 (Feb. 8, 2024 04:01:32)

pika_boo
Scratcher
100+ posts

Repeat help

Use the mod block
I am currently experimenting with values…

Last edited by pika_boo (Feb. 8, 2024 10:09:11)

pika_boo
Scratcher
100+ posts

Repeat help

If you want to loop 53-55
delete the
repeat until <(costume #) = [56]>
next costume
end
(don't delete the wait)

Then insert:
switch costume to ((((costume #) - (1)) mod (3)) + (53))

Hope that helps!

Last edited by pika_boo (Feb. 8, 2024 10:09:45)

deck26
Scratcher
1000+ posts

Repeat help

But are you repeating another set of costumes at another point? Not sure why you'd have the other 52 costumes otherwise. Anyway, if that is the case, you'd be better with a script that looped within a set of costumes defined by a min and max which you can change to suit the current situation.

pika_boo wrote:

Then insert:
switch costume to ((((costume #) - (1)) mod (3)) + (53))

Hope that helps!

Not quite right - if you're using mod 3 you're only getting 3 costumes (53 to 55). You'd want
switch costume to (((costume #) mod (4)) + (53))
pika_boo
Scratcher
100+ posts

Repeat help

oh whoops my bad I read the question wrong. I am so dumb
Thanks for telling me though

Last edited by pika_boo (Feb. 8, 2024 10:07:35)

Froggy_Man1
Scratcher
10 posts

Repeat help

yo thank you so much! it works now!

Powered by DjangoBB