isTouching not working for a student


#1

Hi,

I have a student that cannot get the isTouching command to work, and hasn’t since the beginning of learning about it. I am not sure why everyone else’s works but his does not. No matter what sprite he puts in first, his computer says it does not recognize the isTouching command. I have attached a couple images for reference. Any help would be greatly appreciated.

Thanks!
Tara


#2

@tara.taylor

Hi Tara!

Thanks for including the error code on the bottom. It looks like the code is trying to use the method isTouching on hero, but hero is not defined. That probably means that this line of code is running before you have created the sprite and stored it into the variable “hero”.

Elizabeth


#3

I accidentally posted the same image twice. Here is the other picture and this is at the top of the code:


#4

Without seeing the entire project, it’s hard to know for sure, but it appears that the code in line 45 is getting called before you create the sprite in line 9.