Unit 3, Lesson 14: Interactive Card Question

Hey everyone! I have a question about the Interactive Card project. I have a student trying to use a sound effect, but every time the condition is met the sound effect keeps looping. I have tried everything I can think of to no avail. I am hoping someone here can help me out. Here is a screenshot of the code used in the draw loop.

1 Like

Joey,

Anyway you can share the project to look at it? I believe the problem is in the nested if statements. Two of the â€śifâ€ť conditions are the same if, which both shouldnâ€™t be needed (ship.y <= 100). If the nested loop with the sound was and â€ś==â€ť to 100 it would play and then the ship could move to 99 or 101 and it would stop. Again, just making guesses hereâ€¦

Thank you for taking a look.

It seems to me that once both conditions are met, there is nothing to change the fact that ship.y will be set to 100 at line 69 and will be that forever thus always playing the sound.

Ok, that makes sense. Is there another way to stop the motion of the ship without setting ship.y to a specific number? If that piece of code isnâ€™t in there the ship/explosion would keep moving.

You can stop a spriteâ€™s motion by setting its velocityX and velocityY to zero. But here, since the motion is caused by directly changing the x value, I would suggest something different. Wait to set visibility of the ship to false inside the if statement that plays the sound and use itâ€™s visibility as the trigger to play. That way, once it is no visible, it wonâ€™t play again.

``````if (ship.visible)
{
playSound();
ship.visible = false ;
}
``````

Thank you! Here is what I ended up doing and it seems to have done the trick.

I can show the other way you described, however, as a good example that there are multiple ways to complete the same task in programming.

For sure. This is one of the reasons why I think programming is so fun. So many solutions.

Ok, Iâ€™ve got another challenge. Here is the link to the studentâ€™s interactive card. https://studio.code.org/projects/gamelab/_tKsiQFuXUJMiQnnuRkpDreqD7erZkDmy7cA05EqDKw

When she is in Game Lab, the program works just fine. The â€śsharkâ€ť jumps up to eat the bird when the up arrow key is pressed and the fisherman sprite changes. When anyone clicks on the link, however, what you see is what they see. Iâ€™m not sure where the issue in her code lies, if any.

Hi Joey,

Can you explain what the student wants to happen and what is happening instead? I donâ€™t know whether Iâ€™m seeing the intended behavior or the bug. The program is doing exactly what I would expect from the code.

Thanks,
Elizabeth

Yes. So, when the program loads in Game Lab, the shark is on the bottom, the bird is in the air, and the fisher is standing on the bank. Nothing is blinking. When you press the up arrow key, the shark jumps up and the bird disappears. The fisher sprite changes to something else as well. What you see when it loads is not what is supposed to happen.

Hi Joey,

The reason the sprite is blinking is in the animation tab. The student has used multiple frames to create an animation. For the shark, the frames are a fish and a shark. For the bird, the frames are a bee and a bird.

In order to fix this, the student needs to go into the animation tab and delete the unwanted frames.

1. Click on the animation tab to see the animations for this project.
2. Click on the animation that you want to change.
3. Look between the list of all animations on the left and the big version of the chosen animation on the right. There you will find the list of frames.
4. Hover over the frame you donâ€™t want. A â€śDeleteâ€ť garbage pail will appear
5. Click the delete garbage pail to get rid of the extra frame.
6. Repeat for the other animation.

That should fix the problem for your student. This problem probably happened because the student added the new picture to the â€śframesâ€ť list in the middle of the page rather than the â€śanimationsâ€ť list on the left hand side of the page.

Elizabeth

I see. I missed that when looking at her code. Makes sense. Thank you!

I am back with another problem. I had multiple students today who couldnâ€™t get any text to show up using the drawing commands. Here is an example of one studentâ€™s card:

We tried moving the blocks around to different positions to no avail (both inside and outside the draw function). Iâ€™m not sure if it has something to do with the background being a sprite, but the students who had issues all used sprites as backgrounds. Any ideas?

Hi Joey,

The background sprite is covering up the text. The text command will need to come after the â€śdrawSpritesâ€ť command, or else it will be under all of the sprites and covered up.

Elizabeth

I have students that are having difficulty making their interactive cards work properly. I am attaching the links to the projects.

Iâ€™m having trouble figuring out how to make the eggs disappear. It has no problem becoming not visible outside of the if statement but in the if statement it wonâ€™t disappear.

Erik:
He wants his bunny to move right and left using the error keys.

Cindy Klabunde
CF2 Teacher

I have students that are having difficulty making their interactive cards work properly. I am attaching the links to the projects.

Bryce:
The eggs shake but when the shake count is over the eggs freeze up and wonâ€™t move

Cindy Klabunde
CF2 Teacher.

I think Aiden needs to create his sprites outside the draw loop, as they are being created each time the loop runs right now.

For Bryceâ€™s project, after 40 shakes, he tells the eggs to disappear (and they do), but it doesnâ€™t appear that they disappear because the old drawings of them are still there.

This should be a quick fix by just adding a background block into the draw loop (even a white one if thatâ€™s what your student prefers).

Good luck!

Mike

In addition to what was suggested for Aidan (that he create the sprites outside of the draw loop), he also needs to add a background block inside the draw loop as the eggs ARE actually disappearing, but the old drawings of them arenâ€™t being covered up. A background block inside the draw loop covers up the old egg before drawing a new one. It may actually work while still creating the sprites in the draw loop, but itâ€™s better to create them first.

Erik has a few things I would suggest â€¦ one, you only need one â€śdraw spritesâ€ť block (inside the draw loop).

The main issue, though, is that he has created a bunny and then after creating the bunny, he sets the bunny (itself) to equal 0.9 (a number). Maybe he meant for that to be bunny.scale = 0.9; As is, the bunny is no longer a sprite, but rather a number, so when he is telling it to move left or right, the computer doesnâ€™t know what it means to move the number left or right.

Hope this helps!

Mike