Discuss Scratch

New to Scratch
8 posts

clone firing bug

So I've been making a tower defence game and I have a bug that basically when you place down multiple towers (which are clones) and an enemy is close enough for them to fire at, only one tower fires. This might not make much sense but here's the game link: https://scratch.mit.edu/projects/491325321/
1000+ posts

clone firing bug

My impression is that you get the tower to global variables to store its x and y position and then broadcasts fire. But each clone is doing this so the fire receiver can only respond to whichever tower did it most recently. One clone sends the broadcast to fire but before that is fully acted upon another clone has reset the varialbes so the first tower's x and y position are no longer stored.

The easiest way to get different clones to fire projectiles is to make the projectiles part of the same sprite as I show in method 2 here https://scratch.mit.edu/projects/111228685

Otherwise you'll probably need the towers to add their x and y positions to a pair of lists (and perhaps one for tower type) and the projectiles delete the list items as they react to them. The projectile sprite could then jsut be waiting until one of the lists is not empty rather than needing to receive a broadcast.

Powered by DjangoBB

Standard | Mobile