Help with text appearing in a conditional in U3 L14 cards

Hello,
Several of my students are trying to make text appear when a condition is met, but the text is not appearing. Can anyone help me with this code to see why the text is not appearing? Thank you in advance. I put a little space around the part we are struggling with. Everything works except the text appearing.

var pinetrees = createSprite(200, 200);
pinetrees.setAnimation(“pinetrees”);
var kangawoo = createSprite(200, 80);
kangawoo.setAnimation(“kangawoo”);
var pondah = createSprite(330, 250);
pondah.setAnimation(“pondah”);
kangawoo.scale = 0.3;
pondah.scale = 0.3;
var trex = createSprite(215, 265);
trex.setAnimation(“trex”);
trex.scale = 0.3;
var bear = createSprite(68, 204);
bear.setAnimation(“bear”);
bear.scale = 0.3;
function draw() {

if (keyDown(“right”)) {
kangawoo.x = kangawoo.x + 3;
pondah.x = pondah.x + 3;
bear.x = bear.x + 3;
if (kangawoo.x >= 345) {
kangawoo.visible = false;
fill(“blue”);
textSize(50);
text(“HappyBirthdayKendog”, 250, 50);
} else {
kangawoo.visible = true;
}

}
if (keyDown(“left”)) {
kangawoo.x = kangawoo.x - 3;
pondah.x = pondah.x - 3;
bear.x = bear.x - 3;
}
World.frameRate = 25;
if (keyDown(“space”)) {
trex.rotation = trex.rotation + 5;
} else {
trex.rotation = trex.rotation - 5;
}
if (pondah.x <= 210) {
pondah.visible = false;
} else {
pondah.visible = true;
}
drawSprites();
}

Hi Debbie,

Here is some code one of my students used to have text appear when a condition is met.

if (skier.x < 183) {
skier.visible = false;
snowman.visible = true;
if (snowman.visible) {
//merrychristmas
stroke(“black”);
strokeWeight(6);
fill(“yellow”);
text(‘Merry Christmas’, 250, 179);
}

If this doesn’t help, can you please share a link to the project so we can look at what is happening.

1 Like

Thanks! I finally figured out what the problem was. The background was a sprite, so it was overwriting the text each time the loop refreshed. We first tried drawing a background in the conditional. But, it still didn’t work until we moved the draw sprite to the top of the loop. By moving the draw sprite to the top of the loop, the text became visible. This has fixed all of the text issues my students have been having. :slight_smile:

The new code that works:

var pinetrees = createSprite(200, 200);
pinetrees.setAnimation(“pinetrees”);
var kangawoo = createSprite(200, 80);
kangawoo.setAnimation(“kangawoo”);
var pondah = createSprite(330, 270);
pondah.setAnimation(“pondah”);
kangawoo.scale = 0.3;
pondah.scale = 0.3;
var trex = createSprite(215, 265);
trex.setAnimation(“trex”);
trex.scale = 0.3;
var bear = createSprite(68, 204);
bear.setAnimation(“bear”);
bear.scale = 0.3;
World.frameRate = 25;
function draw() {
drawSprites();
if (keyDown(“right”)) {
kangawoo.x = kangawoo.x + 5;
pondah.x = pondah.x + 5;
bear.x = bear.x + 5;
if (kangawoo.x >= 345) {
kangawoo.visible = false;
if (kangawoo.visible === false) {
background(“yellow”);
fill(“blue”);
textSize(20);
text(" Happy Birthday Kendog", 200, 200);
}
if (kangawoo.x >= 344) {
kangawoo.visible = true;
}
}
}
if (keyDown(“left”)) {
kangawoo.x = kangawoo.x - 5;
pondah.x = pondah.x - 5;
bear.x = bear.x - 5;
}
if (keyDown(“space”)) {
trex.rotation = trex.rotation + 7;
} else {
trex.rotation = trex.rotation - 7;
}
if (pondah.x <= 210) {
pondah.visible = false;
} else {
pondah.visible = true;
}
}

1 Like

Have a Great Friday! Code on!!!

2 Likes

Hi,

My students are trying to make text disappear as a result of user input with no luck. Nothing seems to work. Help!!!

It sounds like the challenge the students are having is that they want things to disappear and stay disappeared after a key has ben pressed. The problem is probably that the text doesn’t get drawn on the iteration of the draw loop when the key is pressed, but that on the next iteration, because the key isn’t pressed anymore, the text is drawn again. You might have to use a variable to save the information about whether the text should be drawn or not. That would involve at least two conditionals. The first conditional would set a drawText variable to false when user input is detected, and the second conditional would draw the text when drawText variable is true.

If that’s not what you’re looking for, maybe you can share a link to the student code so we can see what’s going on.

Elizabeth

Thanks, Elizabeth. That’s exactly what I found, so glad I’m on the right track :slight_smile: