I’m having one of those moments.
I’m making a little risk of rain clone and I’m having problems picking up the items. If I spawn two items I can only ever pick up the last one created.
Now, this is a problem I help troubleshoot for my students all of the time. Typically they have used global variables and not the parameters in the overlap block. But, holy hera, I cannot find what I’ve done wrong here. Can someone help figure out what I’m missing please?
Link to the project
Oh sorry this was supposed to be tags under “help”
This one is indeed a variation of the same bug you mentioned, where you’ll e.g. have a destroy overlap that destroys another block. The most important thing to note is that
sprite a will only ever equal
sprite b if they were made from the same call to
sprite  of kind [etc] (or equivalent block that created it).
There are several ways to fix this sort of thing with varying complexity / correctness, so I’ll list out a few that might be helpful:
- If the image is just a power up like this one with a static image, you can compare the sprites image with the
picture is equal to  block in the images category under advanced. This one is a little ‘unstable’, though – if you do anything to modify the sprites image (e.g. animate it, apply a particle effect like disintegrate that removes parts of the image, change a color in the image, or modify the image in the image editor after copying it over) you’ll end up with buggy code as the images won’t be ‘equal’ anymore https://makecode.com/_9kwW25dH3fjH
- You can pick another kind for the power up. There is little cost to adding an extra kind, and it can make it easier to add separate effects for power ups later on – that is, you won’t need to nest each overlap you add in an extra conditional statement. Doing this may be annoying if you later on want to aggregate all of them, or apply an action to all powers ups (e.g. when you add a second level and want to destroy all the power ups to move on, you’ll need to destroy each kind separately) https://makecode.com/_d7DD6JcMuAYV
- Attach another value to the sprite to indicate what kind of sprite it actually is. This will be similarly stable as option 2, and makes it so you still can keep track of things on the basis of their kind. This is most easily done with the
arcade sprite data extension, which exposes some blocks that can add onto a data field we keep on each sprite:
The extension adds these blocks to the bottom of the sprite category
Then you can make the check work like this https://makecode.com/_e8JVbwia2TxK:
Note you will have to be careful of capitalization / whitespace differences – it might be helpful to create a variable for each power up that is just the name of the power up so you don’t have to copy and paste the same string all over the place and look carefully for extra spaces. (As a side note writing up the post also made me notice that the arcade sprite data
set sprite image to  block is broken as it only takes in the default gallery images and you can’t drag it in; I’ll try to remember to fix that tomorrow >.>)
Hope that helps!
Thank you so much for you clear explanation of both the issue and your examples of how to fix them.
I’ll be going with option one since the images are static but it is good to see the data extension in use.