Errors in two different if-statements Unit 3, Lesson 27

Hi,

I’m looking for any guidance in debugging the following errors:

  • Problem #1: Trying to figure out why a student’s sprite animation frames aren’t moving as expected.

  • Problem #2: There is a problem with the if-statement on line 91. It doesn’t trigger the player sprite to move across the rail sprite as expected.

Here’s the link to the project: [Game Lab - Code.org]

  • For problem #1: There are 3 if-statements that should trigger background changes. They all use sprite animations with multiple frames. The first two work as expected; however, the third animation on line 44 only draws the first frame of the animation.

For problem #2: I am aware that the player’s velocityX is set to get the value of the rail’s velocityX, but the if-statement doesn’t seem to trigger any changes. I’ll admit that it’s very difficult (at least for me) to move the player across the rail.

I’m stumped on both of these issues.

Hi @mlbradley,

I love the detail in this game. The skateboarding character is great!

As for the background for problem #1, when I isolated each if statement and had them run if the score is 0, they worked fine. I’m thinking the issue is the logic. If you look at the code, the second if statement runs if the score > 9 and the third if statement runs if the score>19. What happens if score =20? Then both if statements are true. I would change the second if statement to be more precise with a compound AND boolean which just means two statements would need to be true. Here is the documentation on the compound and statement. So, the 2nd background should appear when the score is greater than or equal to 9 AND the score is less than or equal to 19 ((score>=9) AND (score<=19)). That should fix your background.

As for the the rail sprite, I think the issue is just cropping the sprite. In the animation tab, click on the crop button. When I tested it after cropping, it was pretty easy to get the character to “jump” the ramp. When you don’t crop the sprite, the entire canvas is collidable instead of only the sprite.
crop

Let us know if you have more questions after trying these tips.
~Michelle

Hi Michelle,

Thank you so much for your tips. I can’t believe I missed that logic issue in the background if-statements. Once I applied your logic, it worked just great!

For the second issue, I did crop the sprite, but because I’m so terrible at jumping the rail, I am going to have my student try it tomorrow to see if works better for him.

Thanks once again!

Michelle
BTW, love your name :grinning:

1 Like

Ha! Love your name too!!!
Yep - let us know if cropping helps.

Hi Michelle,

Thank you for all your help again. My student decided to take his project in another direction regarding the rail sprite so I didn’t get to see how that worked. He was able to make his backgrounds run as expected with your tips on the compound if-statement. Much appreciated!

Michelle