Conditionals help

I have a student who is creating a game in Unit 3, Lesson 27. He’s trying to add a conditional so that when his character reaches the finish line, the words, “you win” appear on the screen. We have the conditional set up but it isn’t working. Any ideas?

It isn’t shared properly.

That’s the only link I can copy. Here’s the copy of the code…

var sprite = createSprite(200, 200);
sprite.setAnimation(“sports_track_1”);
// Create your variables here
var person1 = createSprite(70, 350);
person1.scale = 0.3;
person1.setAnimation(“red_hoodie_hands_in_hoodie_1”);
var person3 = createSprite(270, 350);
person3.scale = 0.3;
person3.setAnimation(“blue_hoodie_hands_in_hoodie_1”);
var person4 = createSprite(200, 350);
person4.scale = 0.3;
person4.setAnimation(“blue_shirt2_1”);
var person5 = createSprite(135, 350);
person5.scale = 0.3;
person5.setAnimation(“brown_sweater_hands_in_pockets_1”);
var person6 = createSprite(330, 350);
person6.scale = 0.3;
person6.setAnimation(“yellow_shirt_hands_in_pockets2_1”);
var finishline = createSprite(200, 5);
finishline.scale = 0.6;
finishline.setAnimation(“finish line.jpg_1”);

// Create your sprites here

function draw() {
if (keyWentDown(“space”)) {
person1.setAnimation(“red_hoodie_hands_in_hoodie_1”);
person1.y = person1.y - 13;
}
if (keyDown(“space”)) {
person3.setAnimation(“blue_hoodie_hands_in_hoodie_1”);
person3.velocityY = -1;
person4.setAnimation(“blue_shirt2_1”);
person4.velocityY = -2;
person5.setAnimation(“brown_sweater_hands_in_pockets_1”);
person5.velocityY = -2.5;
person6.setAnimation(“yellow_shirt_hands_in_pockets2_1”);
person6.velocityY = -1.5;
}
if (person1.isTouching(finishline)) {
fill(“black”);
textSize(10);
text(“you win”, 200, 200);
}
drawSprites();
}
indent preformatted text by 4 spaces

You could remix the project and then publish and post a link.

It is possible in games like these for one sprite to jump over another sprite without ever touching it. Sprites don’t move to every location in between. They jump.

@gretchenreeves,

It appears you don’t have sharing enabled for your students. If you have the ability to enable the sharing and/or remix the project yourself and then send us the shared link, we are happy to take a look.

Because we can’t see the sprites and can’t visualize what is happening in a situation like this, the code itself won’t help us to troubleshoot as it isn’t likely a typo, but rather as @jdonwells says, a potential collision issue due to the velocity of the sprite that may be skipping over the finish line without making a direct hit.

If you can’t share, you may try “slowing down” the velocity which could cause a more direct collision.

Best wishes! If you can find a way to share it, we’d be happy to take a look at it.

Mike

I remixed and then shared the link below. I hope this one works.

@gretchenreeves,

I’ve played around with this and was able to get it to work. There’s nothing wrong with the code, but the “finish_line” sprite is somehow corrupted. I’ve seen this happen before and I can’t figure out why or how it gets that way, but here’s what I did to get it to work.

  1. Duplicate the finish line
  2. Delete the original finish line
  3. rename the copy to be the same as the original

Alternately, you could delete it and try uploading it again.

Good luck!

Mike