There's a section of block code which on rare occasions, doesn't do it's job

I cam across a PVZ project which seemed abandoned, so for fun I wanted to redo and complete it over the holidays.

The Problem: I have a bit of block code which deals with the interaction between Torchwood, and peas fired from Peashooter and Repeater. A majority of the time it works, it becomes a flaming pea, but sometimes the pea passes straight through, and I can’t figure out why. I even tried adding an invisible sprite in front of torwood to light any peas that weren’t initially lit, and that didn’t seem to work Either…

The game: https://arcade.makecode.com/S27656-07658-27612-60434

The original creator’s game, just for acknowledgment: https://arcade.makecode.com/S93167-05100-47201-67587

Maybe use a forever block? Or maybe on game update block?

Have you seen the code? It’s one of those "On sprite of kind A overlaps with othersprite of kind B " blocks, I can’t put that inside a forever or game update block, or at least I wouldn’t know how to do it…

This one’s a tough one, @JaidenThePerson !

The only thing that I can see is that the switch only happens if the projectile’s z-index is zero. Is there any reason why any of those projectiles would have a z-index that isn’t zero before they hit the torchwood?

Try moving the repeater out of the way and see if the single shooter always works. Then swap them and see if the repeater always works. There might just be something weird happening only when they’re both firing.

I’ll try digging into this tonight, too, after I get home from work.

1 Like

Oops, sorry, I didn’t look at the code. Maybe do this: https://arcade.makecode.com/S65692-54736-60044-76918 Check inside the code to see what I mean, I hope this works.

I fixed it here is the link https://arcade.makecode.com/S23763-50723-09894-24057 There was a varibule that wasn’t the right type, I fixed it, it works. Simple

2 Likes

I think I’ve fixed it: https://arcade.makecode.com/S50978-12446-34234-75789

I was changing the projectile’s z-index as a modifier for an individual projectile, as I wanted projectiles that have been set on fire to deal an extra 20 damage. I also had both the peashooter and repeater in the same lane because I was testing if the torchwood could handle a larger amount of projectile interactions.

The Ïf projectile z-index = 0 then"block was there because I was originally changing its index by one, which I later changed to just setting it to 1. This made the if block obsolete, and after I removed it, all projectiles would be lit with no problem! The only slight issue I had after that was that the animation would continuously reset until it finally passed the torchwood. Still, I fixed that by having a small sound effect play at the end of the code so that it will have already passed the torchwood by the time the code tries to run again (resetting the animation).

Thank you! I wouldn’t have been able to fix it if you didn’t mention the z-index!

1 Like

Wow thank you so much! How did you fix it? I can’t seem to find the change you made :mag:

There was a variable that said “projectile” instead of dragging down the “Sprite” inside the block “On Sprite kind Projectile Overlaps with Sprite kind Torchwood at location”.

1 Like

Ooh, thank you, that’s way more efficient than the way I tried to fix it, thank you!