I want the variable charge to rest to 100 when the player is standing on the object charger

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lonely coder

I’m making a game with a robot as the main character. The robot has a limited amount of jumps until he needs to stand of the “charger” to reset it. Does anyone have anyone have any ideas on how I can rest the charge variable when standing on the “charger”?

 elif Input.is_action_pressed("ui_up"):
	if charge >= 1:
		if on_ground == true:
			velocity.y = JUMP_POWER
			velocity.x = 0
			on_ground = false
			charge = charge - 20

This is the code on how I limit the jumps but I don’t know how to reset charge.

:bust_in_silhouette: Reply From: eons

You can make a setter or a function to increase the charge, then use min or clamp to control the values.

The piece of code to control the value should be like this

charge += something; #charge can be > max_charge here
charge = min(charge,max_charge) #cut charge to the max value

Clamp can be used to control min and max values.