Discuss Scratch

ChillsChill
Scratcher
22 posts

Previous costume button

I need help on my code. As you allready know there is a Next Costume button:

next costume


But there is not a Previous Costume button?? How do I make one?







previous costume
FateSealer
Scratcher
100+ posts

Previous costume button

You can rely on the costume number:

(costume #)

and on this block:

switch costume to (some number)
NormalMaker
Scratcher
500+ posts

Previous costume button

FateSealer wrote:

You can rely on the costume number:
switch costume to (some number)
That isn't the same as previous costume.
switch costume to ((costume #) - (1))
A_Dilophosaurus
Scratcher
31 posts

Previous costume button

Why did the replies only appear once I posted something?

Last edited by A_Dilophosaurus (March 24, 2021 15:06:14)

Lemonerdy
Scratcher
44 posts

Previous costume button

Here's what you can do:

when this sprite clicked
switch costume to ((costume #) - (1))

The costume # represents the number of the current costume it's on. So if it changes to that number minus one, it will go to the previous costume.

Hope that helps!
FateSealer
Scratcher
100+ posts

Previous costume button

Yes, @NormalMaker, your answer is the proper answer to the question. My answer was too generic.
ChillsChill
Scratcher
22 posts

Previous costume button

Lets say there is a sprite in my game with 4 costumes. If I want the animation to go like this, 1 2 3 4 , 4 3 2 1. like it is cycling through and then back. How do i do that?
awesome-llama
Scratcher
1000+ posts

Previous costume button

A_Dilophosaurus wrote:

Why did the replies only appear once I posted something?
The other posters replied quicker than you. By the time you posted, they already did so when the page loaded, that's when you can see that it happened already. Just look at the post time. All within minutes of each other.



ChillsChill wrote:

Lets say there is a sprite in my game with 4 costumes. If I want the animation to go like this, 1 2 3 4 , 4 3 2 1. like it is cycling through and then back. How do i do that?
You could use two loops.

forever
repeat (4)
next costume
end
repeat (4)
switch costume to ((costume [number v]::looks) - (1))
end
end
ChillsChill
Scratcher
22 posts

Previous costume button

Heres my code it dont work
when green flag clicked
forever
next costume

when green flag clicked
forever

if <(costume #) = [4]> then

switch costume to ((costume #) - (1))
ChillsChill
Scratcher
22 posts

Previous costume button

THANK YOU @awesome-llama You live up to your name btw

FateSealer
Scratcher
100+ posts

Previous costume button

switch costume to [1 v]
repeat (3)
next costume
end
repeat (3)
switch costume to ((costume #) - (1))
end

Last edited by FateSealer (March 24, 2021 15:20:28)

7salad3salad
Scratcher
1000+ posts

Previous costume button

ChillsChill wrote:

I need help on my code. As you allready know there is a Next Costume button:

next costume


But there is not a Previous Costume button?? How do I make one?







previous costume

You can do these things that other people are saying and then I would make it into a custom block.
ChillsChill
Scratcher
22 posts

Previous costume button

Thank you everyone!
ChillsChill
Scratcher
22 posts

Previous costume button

I used the script for this game https://scratch.mit.edu/projects/505352495/ TYSM!
FateSealer
Scratcher
100+ posts

Previous costume button

I know, it is basically a closed topic, but I cannot resist sharing my code below. It uses only ONE loop inside the forever loop. (The solutions above needed two loops inside the forever loop).

switch costume to [ costume 1 v]
set (i v) to [1]
forever
repeat (3)
wait (0.4) secs
switch costume to ((costume #) + (i))
end
set (i v) to (() - (i))
end
awesome-llama
Scratcher
1000+ posts

Previous costume button

FateSealer wrote:

I know, it is basically a closed topic, but I cannot resist sharing my code below. It uses only ONE loop inside the forever loop. (The solutions above needed two loops inside the forever loop).

switch costume to [ costume 1 v]
set [i v] to [1]
forever
repeat (3)
wait (0.4) secs
switch costume to ((costume #) + (i))
end
set [i v] to ((0) - (i))
end
Multiple loops isn't always bad though. For a lot of things a simpler method is better than a more elaborate one. Still good practise for programming though if you can challenge yourself with such limitations.
FateSealer
Scratcher
100+ posts

Previous costume button

Yes, @awesome-llama. My code is not more effective. It is just more compact. At least, for me.

Powered by DjangoBB