Error: Overlap can only be checked between Sprites or groups

Hi Anisa,

Yes, that works. Here’s the rundown of the debugging process for this.

The message “overlap only works with sprites” most likely means that the program was expecting a sprite, but got something else. So, something that the programmer intended to be a sprite was, in fact, not a sprite.

This can be caused be a couple different things. Maybe the programmer accidentally used the wrong variable, thinking it contained a sprite when it did not. More likely, the programmer had stored a sprite inside a variable, then stored SOMETHING ELSE inside the variable, knocking the sprite out of the variable so it is no longer accessible through that variable name (even though the sprite still exists and can be drawn to screen through drawSprites).

Based on the fact that this is line 117, I’m going to assume that the player.isTouching(star2) is the problem for a couple reasons. First, there’s nothing about the code in line 116 or 117 that would REQUIRE a sprite, even though there are sprites there. Second, I know that isTouching checks for whether things are overlapping, so there’s a good chance that isTouching uses an overlap method inside of it.

Given that, I will look through the code and see whether there is somewhere that player or star2 is assigned a value that is not a sprite. A quick skim of the program shows that on line 77, star2 is assigned a random number. This explains the problem, and why it takes a while to show up, because this code is only run AFTER star2 goes past the vertical 400 position. At that point, a random number is stored into the star2 variable and there is no longer a sprite stored in the variable. So, when line 115 calls player.isTouching(star2) there is an error, because isTouching cannot check whether a sprite is touching a number.

That may not be the only place that this is a problem, but similar steps should allow you to find all the bugs.

Elizabeth

1 Like