Need help with an error


#1

I have a few students that have been working on Unit 3 Lesson 22 to complete their own games. One day their code works fine, they shut the program and make no further changes. The next when they log back in, they get a Function error on line 42 (It’s always line 42 no matter what). I’m at a loss and the students are stuck.

Any ideas? I’ve shared a link to one of the student’s games here: https://studio.code.org/projects/gamelab/w0y1eKuyzCZ76IUth2hUJ4FLA1IpZAEb3UyymFEx3BE

Thanks!


#2

@smcelwrath

Hi Stephanie,

Really interesting bug! I’ll start off with the background of what happened and the debugging process in case you want to tell your students, but if you want you can skim to the end.

Usually an error message like this means that you are treating something as a function (calling it), even though it is not one. This can either be because you forgot to define the function, misspelled it, or (most commonly) have redefined your function as something else in a different place in the program.

In this case, it’s a little more tricky. The error is showing up right after the conditional that asks about Chick1.isTouching(Fence). Even though that’s not a function on its own, the isTouching method acts like a function when it’s attached to a sprite. When it’s NOT attached to a sprite, though, it doesn’t mean anything.

If you scroll down to line 115, you’ll see that the value of Chick1 is set to true or false. That means that it’s not a sprite anymore, so next time the program checks for Chick1.isTouching(Fence), the isTouching method doesn’t mean anything anymore.

I’m not sure exactly what the students were intending to do in setting the values of their sprites to true or false (maybe destroy them or set their visible property to false?), but fixing that should fix the program.

Elizabeth


Can't figure out what is wrong Lesson 3 final game-help
Can't figure out what is wrong Lesson 3 final game-help
#3

Thank you so much! She actually had made a variable and named it the same as her sprite. So when she referred to the variable being true or false it confused the code. She changed the code for the variables and now it’s working perfectly! Thank you so much for your help and quick response!