Discuss Scratch

artistically12
Scratcher
21 posts

How do I switch between just 2 costumes when I have many?

Essentially, I want to do something like this:

when I receive [.... v]
repeat (10)
switch costume to [costume1 v]
switch costume to [costume2 v]
end

This isn't working for me since I have many costumes, what should I do?
Ommud
Scratcher
54 posts

How do I switch between just 2 costumes when I have many?

I think this code is ok.

It won't interfere with the other costumes.

The problem might be that there is no “wait () second” blocks between so it won't show it is changed, maybe it should be like this?

when I receive [ v]
repeat (10)
switch costume to [costume1]
wait (1) secs
switch costume to [costume2]
wait (1) secs
end

I hope this helps

Last edited by Ommud (Jan. 18, 2021 04:33:29)

badenet
Scratcher
5 posts

How do I switch between just 2 costumes when I have many?

artistically12 wrote:

Essentially, I want to do something like this:

when I receive [.... v]
repeat (10)
switch costume to [costume1 v]
switch costume to [costume2 v]
end

This isn't working for me since I have many costumes, what should I do?

try
when green flag clicked
repeat (10)
switch costume to [1 v]
wait (0.03) secs
switch costume to [2 v]
wait (0.03) secs

end


0.03 gives a smooth frame rate, however the time is your choice. The reason the original script you have doesn't work is because the switching is so rapid it looks the same to our eyes.
deck26
Scratcher
1000+ posts

How do I switch between just 2 costumes when I have many?

It helps to think of things this way. Scratch will only refresh the frame once per cycle. If you have a loop setting different costumes only the last costume change is actually going to be seen as that's when the frame is redrawn. By adding a wait block you're allowing the frame to be refreshed before the end of that loop so you see the costume before the wait block and the second costume appears in a later screen refresh. If you have no other scripts running the screen would just need to be refreshed when the script reaches each wait block and, presumably, at the end of the loop.
artistically12
Scratcher
21 posts

How do I switch between just 2 costumes when I have many?

Thanks everyone, those helped

Powered by DjangoBB