Discuss Scratch

DollyC
New to Scratch
15 posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

I would like Sprite 1 to change into Costume 2, after it has come into contact with Sprite two 3 times.

I haven't got any script for this yet, as I don't know how to do this at all.

Help in this area and examples if possible, would be appreciated. Thank you in advance.
Endy777
Scratcher
94 posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

I can help you check out my project Endy on picnic.Go inside and go in Endy's scripts you will see something like this:
when green flag clicked
if <> then
<touching [paws v] ?>
end
broadcast [ v]

hOI there!I really like Undertale and it's AU's:Underfell,Underlust,Horrortale…But mai favs are simply Undertale,Aftertale and famous GZtale.

THEY ARE MINE SANSPAIS…

Some Undertale quotes that are related to me a lot:

''What do we need to be a good friends?Some bad food,some bad laught…What do you think,kiddo?''
''ANIME IS REAL,RIGHT?''
awesome-llama
Scratcher
1000+ posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

Put this in sprite 1:
when green flag clicked
repeat (3) // how many times it should touch
wait until <touching [sprite2 v] ?>
wait until <not <touching [sprite2 v] ?>>
end
switch costume to [2 v]

Edit: Ninja'd

Last edited by awesome-llama (Aug. 23, 2016 10:59:36)



DollyC
New to Scratch
15 posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

That hasn't worked for some reason…..

How would you write the script to say:

If Sprite 1 receives ‘Broadcast 1’ three times, it changes costume?
Endy777
Scratcher
94 posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

Endy777 wrote:

I can help you check out my project Endy on picnic.Go inside and go in Endy's scripts you will see something like this:
when green flag clicked
if <> then
<touching [paws v] ?>
end
broadcast [ v]
sorry for this

hOI there!I really like Undertale and it's AU's:Underfell,Underlust,Horrortale…But mai favs are simply Undertale,Aftertale and famous GZtale.

THEY ARE MINE SANSPAIS…

Some Undertale quotes that are related to me a lot:

''What do we need to be a good friends?Some bad food,some bad laught…What do you think,kiddo?''
''ANIME IS REAL,RIGHT?''
DollyC
New to Scratch
15 posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

I've tried replacing the ‘when green flag clicked’ that awesome-llama posted, with ‘when I receive Broadcast 1’ and it didn't work.
Candylanguagegirl
Scratcher
1000+ posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

DollyC wrote:

That hasn't worked for some reason…..

How would you write the script to say:

If Sprite 1 receives ‘Broadcast 1’ three times, it changes costume?
when I receive [broadcast1 v]
change [foo v] by (1)

when green flag clicked
set [foo v] to [0]
forever
if <(foo) = [3]> then
show
end
end
Put both of those in the sprite you want to show.

Last edited by Candylanguagegirl (Aug. 23, 2016 11:15:40)


~Fail spectacularly~
DollyC
New to Scratch
15 posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

I've also tried what Endy777 put, but it hasn't worked.

Sorry, what does foo mean, Candylanguagegirl?
DownsGameClub
Scratcher
1000+ posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

DollyC wrote:

I've also tried what Endy777 put, but it hasn't worked.

Sorry, what does foo mean, Candylanguagegirl?
Do you have the broadcasting script set to broadcast 1? If not, then reset the broadcasting script as the broadcast won't fire properly.

–DGC
Scratcher since Aug. 2015 +++ Fire Alarm Enthusiast +++ College student studying fire protection engineering
DollyC
New to Scratch
15 posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

I have entered the script that candylanguagegirl suggested and it has worked.
However, when it changes costumes the other scripts don't work…. Any ideas anyone?
DollyC
New to Scratch
15 posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

DownsGameClub - yes, I have tried out. Now that I have changed the script, when the sprite changes costume it won't show up or work when I need it to.
pinkieofthepies
Scratcher
500+ posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

DollyC wrote:

I have entered the script that candylanguagegirl suggested and it has worked.
However, when it changes costumes the other scripts don't work…. Any ideas anyone?
foo is the default name for the variable in the scratchblocks plugin.

go to the project link, below, backpack the scripts and use them. they should work. its cluttered, and you will need to change the
when [ space v] key pressed
block to your controlls, or some other thing, but if you press the spacebar until scratchcat touches the circle 3 times, it changes.
https://scratch.mit.edu/projects/118939771/

still here
amylaser
Scratcher
500+ posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

DollyC wrote:

That hasn't worked for some reason…..

How would you write the script to say:

If Sprite 1 receives ‘Broadcast 1’ three times, it changes costume?

The solution is simple.
Use a variable to count how many times Sprite 1 has received the broadcast. For example:
when I receive [Broadcast 1 v]
change [counter v] by (1)
if <(counter) = [3]> then
switch costume to [costume2 v]
end

And just have it so that Sprite 1 receives the broadcast every time it touches Sprite 2.
Actually, you could even remove the broadcast altogether and condense everything into one script. Like so:
when green flag clicked
set [counter v] to [0]
forever
if <touching [Sprite 2 v] ?> then
change [counter v] by (1)
if <(counter) = [3]> then
switch costume to [costume2 v]
end
end
wait until <not <touching [Sprite 2 v] ?>>
end

That last “wait until” block is to make sure the counter variable doesn't keep increasing to infinity while the sprites stay in contact.

Does that help?

Last edited by amylaser (Aug. 24, 2016 07:48:08)


Art, Animations, and Games!


~click one to check it out~
footrot
New to Scratch
1 post

How can you make a sprite change costumes after it has come into contact with another Sprite?

I really need help!I have been trying to get my sprite to change costume when it touches another sprite but it doesn't work.I really don't get it and need help!Please help me!!!
Coke0913
Scratcher
29 posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

DollyC wrote:

I would like Sprite 1 to change into Costume 2, after it has come into contact with Sprite two 3 times.

I haven't got any script for this yet, as I don't know how to do this at all.

Help in this area and examples if possible, would be appreciated. Thank you in advance.


I think I have an answer to your query: (the variable names can be changed)

when green flag clicked
set [ (foo)] to [0]
switch costume to [ v]
forever
if <touching [ v] ?> then
change [ (foo)] by (1)
if <(foo) = [3]> then
switch costume to [ v]

end
end
end

when green flag clicked
forever
say [Agent Coke here, signing off!]
end
DDarby744
New to Scratch
5 posts

How can you make a sprite change costumes after it has come into contact with another Sprite?

can you help me im trying to get my sprite to change costume when my dragon touches my sprite

Powered by DjangoBB