Practice: Creating a jump pad (Changing body.jump_number has no effect)

ph-cross

So the practice wants us to limit the number of jumps available after bouncing off a jump pad by adding a line such as the following:



...Which marks the practice as completed.
However, with the way the practice is currently designed, changing the jump_number here does nothing. The game is functionally the same regardless of whether of how you jump on the platform. By default in the practice, you can't triple-jump off the JumpPad because of the code added to the player character on line 26

This code automatically sets our jump_number to 1 (after the JumpPad's code is executed) and allows us to make a double-jump after bouncing off the platform. So changing the variable thru _on_body_entered won't do anything. However, the practice is looking for a change to body.jump_number there to tick the clear flag. As long as you have this line and it doesn't say "body.jump_number = 0," the practice will return a positive.

However, even setting jump_number to 0 in _on_body_entered() will not allow you to triple jump! The player character is already handling the glitch that we're meant to be fixing before we touch the code. In other words, we're being asked to fix a glitch that doesn't exist. In fact, you can set body.jump_number to a number that would normally prevent double jumps (i.e 2 or more) and because the player is going to set it back to 1 anyways, you'll always be able to double jump.

body.jump_number = 0, += 1, = 1, = 2, etc. <– all of these modifiers to the jump_number will have the same effect when the game runs.

Switching line 26 in SideScrollDoubleJump.gd to "pass" like this:

will re-enable the triple-jump glitch and allow changing the variable in the JumpPad's code to actually affect the game. I know I was left stumped when the game didn't reflect what the practice text was saying, but luckily the main course mentioned this block of extra code so I was able to figure out what was going on.

Anyways, hopefully this helps any other students out who might be wondering why nothing seems to be different after adding the body.jump_number line.

  • Nathan Lovato replied

    Thanks for bringing this up! It seems like a typo in the practice text in Godot. The character could jump twice after hopping on the pad, not three times. And the change made in the practice is here to have a single jump allowed after getting a stronger jump from a pad.