This extension (thanks to @jwunderl’s sprite utils and the tilemap a* path following extensions) massively helps with tower defense games, so that when multiple sprites are following a path, you can easily determine and target the first sprite!
The extension: kiwiphoenix364/pxt-tower-targeting
Paste the “link” in the search bar at the top of the extensions page and click on the result.
One thing you’ll definitely need to make it not crash is this:
(the array of sprites of kind tower is so that all the towers attack, also, the enemiesinrange true/false piece of code is so that if there are no enemies in range, it won’t attempt to output a sprite value since there are no sprites in range to attack.)
I’ve made an example of how to use this. You might see that I’m using the arcade-sprite-data extension. This extension is very useful and probably essential if you want to have multiple towers/enemy types in your game without making too many blocks or sprite types and also to have attack cooldowns.
If you want to make an advanced tower defense game, you probably will need to have more local variables and assign them as attributes to the projectiles that the towers make (like in my tower defense project.)