Project Interactive Card

[Posts in the debugging category need to have the following pieces of information included in order to help other teachers or our moderator team best help you. Feel free to delete everything in brackets before posting your request for debugging help.]

Link to the project or level: [replace with link to the curriculum or get the “Share” link to a project]

What I expect to happen: On the 5th mouse click, I want the jack o lantern to change to the scary clown (preferably to stop rotating as well)

What actually happens: It never changes to the clown

What I’ve tried: Changed the order of the code. Changed the mouse input to keyboard input.

@nclark1,

Welcome to the forum. I took a look at your project and I think I can help steer you in the right direction.

You used the following code in your project:

if (mouseDown("leftButton") == 5)

Since a conditional statement is by definition a boolean expression (either on or off), it can only equal 1 (on) or 0 (off). So when the mouse button is clicked, it equals 1 and when it isn’t clicked, it equals 0. It can’t equal 5.

What you probably want to do is to create a variable called “clicks” and then each time the mouse button is clicked, that variable could go up by 1. Then, you could check the value of that variable to see if it’s 5 (which would trigger the sprite change).

I hope this helps, but if you still have questions, don’t hesitate to reply and we can continue to help steer you in the right direction.

Mike

var cave = createSprite(200, 200);
cave.setAnimation(“cave_1”);
var vampire = createSprite(72, 209);
vampire.setAnimation(“monster_05_1”);
var wife = createSprite(319, 209);
wife.setAnimation(“monster_01_1”);
var jack = createSprite(168, 284);
jack.setAnimation(“gameplayadventure_11_1”);
vampire.scale = 0.75;
wife.scale = 0.75;
jack.scale = 0.3;

// create a variable to keep track of the number of clicks
// initialize it to zero
var clicks = 0;

function draw() {
if (mouseDown(“leftButton”)) {
jack.rotation = jack.rotation + 5;
clicks = clicks + 1;
} else {
jack.rotation = jack.rotation - 5;
}
if ( clicks == 5) {
jack.setAnimation(“monster_03_1”);
jack.scale = 1.5;
jack.rotation = 0;
}
drawSprites();
}