Student Digging game not working

Hi all-
The problem with not knowing enough javascript is when you have those students who are really gifted and want to do more than you know- and then they need help but you can’t even figure out where to begin. Maybe you all can help me- help my student.

Link to the project or level: Code.org - Game Lab

What I expect to happen: The idea of the game is that the player will be a shovel and you can dig down to try and locate diamonds etc. When the player goes over the area and presses down the mouse key, they should go down into the soil.

What actually happens:
When the code is run, the player moves right-left- up with no issue, but when the user hits the mouse while over the player or any of the soil- everything disappears. An error message comes up- ERROR: Line: 221: TypeError: e.setDefaultCollider is not a function. The error message is associated with these lines of codes…

if (mousePressedOver(counter1)) {
counter1.x = -100;
}
if (keyWentDown(“down”)) {
player.velocityY += 2;
}

What I’ve tried: The student has tried to use an array- with no success. He tried to add a collision but it didn’t give him the effect he wanted.

any help you can give me would be wonderful.

1 Like

Hi @kmcglaun,

Whew! There is a lot going on in that game. Impressive! I believe the error message is coming up because counter1 is just a text string = “A5”. On line 13, he sets counter1=“A5” which gives it the value of the text string “A5” and therefore it does not have any properties of a sprite or group. Line 23 to 26 does not then change counter1 to a sprite variable and make it part of the group. A5 is the actual name of the sprite that he wishes to be moved if it is clicked. So, it should read if(mousePressedOver(A5)). When I changed this, the block disappears when I click it.

I haven’t tested but I assume the same would hold true for line 15 var counter2 = “5”;. On this line, counter2 is simply a text string with the value of 5.

Hope that helps!
Michelle

1 Like

Thank you so much. I passed it on to my student. Sometimes I think I have no business teaching coding and other times- well… thank you.

2 Likes

We all feel like that sometimes- at least I do! I hope you know that game was beyond the scope of the curriculum so kudos to you for giving kids the space to create something so cool!
~Michelle

3 Likes

:smiling_face_with_three_hearts:
شكرا جداhttps://support.code.org/

الشكر موصول :smiling_face_with_three_hearts:https://support.code.org/

1 Like