Help me work out how to program a slam jump. (Boolean variables)

Godot Version

4.3

Question

I’m new to this fellas

I want to be able to increase jump height after doing a ‘Slam’ (in other words, a ground pound), but only after doing a ‘Slam’. So if I want to jump extra high, I have to do a ‘Slam’ before I jump, every time. Here’s what I did:

#Slamming
	if velocity.y > 0:
		states = States.FALLING
	if states in [States.FALLING] and Input.is_action_just_pressed("Slam"):
		states = States.SLAMMING
	if states in [States.SLAMMING]:
		velocity.y += SLAM_GRV
		stun = true
		boost = true #IMPORTANT PART

# Handle jump.
	if Input.is_action_just_pressed("Jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY
		states = States.JUMPING
		if boost == true: #IMPORTANT PART
			velocity.y = JUMP_VELOCITY - 100
			boost == false

I set the ‘boost’ to false in the Jump statement, in hopes of making it so that once I jump after a ‘Slam’, I have to ‘Slam’ again to set the boost to true, in order to gain the extra jump height.

What I’m getting is that I can’t declare the ‘boost variable’ as false, after I set it as true in the same statement. If I can’t do that, then what else am I supposed to do? I hear that using timers for very short intervals leads to bad results, so I’ve avoided using them in this case. Please help because I am proper stumped :confused:

If boost isn’t declared then you will have to declare it. “declaring” a variable is a line that starts with var, in your case var boost should be near the top, near var states or var stun.

When you want to check one value use ==

if velocity.y > 0:
	states = States.FALLING
if states == States.FALLING and Input.is_action_just_pressed("Slam"):
	states = States.SLAMMING
if states == States.SLAMMING:
	velocity.y += SLAM_GRV
	stun = true
	boost = true

Though it looks like this code would change to the FALLING state every frame since velocity.y > 0, maybe another check is in order?

if velocity.y > 0 and states != States.SLAMMING:
	states = States.FALLING
1 Like