Issue with multipul of the same enemy

i have a game with mulitupul mushroom enemys. they walk left until they hit a wall then turn around and move right until they hit a wall. they are all spawned on orange placeholder tiles. wich i use to quickly set there spawn points. but only one of them works at a time. the others play theire animations but cant move. (theres some leftover assets from a previes iteration of the game)
pleas help me fix this https://arcade.makecode.com/S02327-44663-02815-13041

2 Likes

I may be wrong, but it seems like you are using one variable and trying to track all the enemies. As far as I am aware, each variable will only track 1 sprite. I think I once used a list/array to get around this but I don’t know if that actually even worked.

The mushmin variable only holds the most recent sprite created, so it only affects the sprite that is created last. If you want to affect every sprite, you need to use a For loop like this:


That “Array of sprites” block is in the Sprites tab.
Also, you would have to replace all the “mushmin” variables in that block with the “value” block (you have to drag it)

Another thing is that once you set a sprite’s velocity, you don’t have to keep setting it over and over. Also, after adding this code, your “mushmin 1 col direction” thing you have isn’t going to work anymore. Basically, what I’m saying is that, instead of setting a variable, you can just change that sprite’s velocity instead of setting a whole variable to do it, like this:

Now none of your sprites move. Why? Because you never made them move when they were spawned, so let’s do that too:

And we’re done! Everything works!
Have fun, and happy coding!

oh thank you!