# Repeatedly change a sprite on every collision

Hello community,

I’ve no idea if I’ve just over complicated this.
WHAT AM I TRYING TO DO? - I have a dummy sprite which has BOUNCE. (it bounces around like pong ball) but… I have another sprite that sits on top of dummy (hidden) top-sprite. The idea is… if dummy sprite collides with player (another sprite with controls)… then change the top sprite to say … a fireball and if player hit once again… change to another sprite … e.g. iceball.

Like Dodgeball… but the player runs around and avoids being hit… make sense?

So if fireball hits player… reduce xx points… off player’s health and if iceball… then slow player down for xx seconds. I guess this is player variables - right?

QQ: Would I use an array list for this?
I’m thinking, it’s easier to have to top-sprite change rather than the dummy???

Thanks,
Rob

If added this… seems to work.

I added some Trigger Once

But it seems to work sometimes and can ignore the contact… any ideas pls?

Hey, this looks fun.

Could you elaborate on the ignore the contact? Do you mean they get in contact and it only changes once? Or do you mean they get in contact separate reconnect and it doesn’t change?

Sorry I didn’t read the first post.

So I have been learning about variables and I think maybe assigning a variable that changes on collision would work.

Though to be honest now that I think about it, what if the random number that is picked is the same as the one it already was?

That’s a good point.

There should be a simpler way to write this. I would use mod() if zero was involved but this works.

Each time it adds either 1 or 2, if it’s > 3 then set it subtracts 3

1 becomes 2 or 3
2 becomes 3 or 4, if it’s greater than 3 we subtract 3 so it becomes 1
3 becomes 4 or 5, it’s greater than 3 so we subtract 3 and it becomes 1 or 2

Edit: I’m using the new shortened variable syntax, so the last line would be Variable(rand) in the previous syntax.

1 Like

Brill Thanks Guys. I was able to get it done using @Keith_1357’s example.
Thanks @TJCoffman for the assist.

2 Likes