0 votes

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
            $AnimatedSprite.play("jump") 
            charge = charge - 20

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

in Engine by (12 points)

1 Answer

0 votes

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

https://docs.godotengine.org/en/3.1/classes/class_@gdscript.html#class-gdscript-method-min

Clamp can be used to control min and max values.
https://docs.godotengine.org/en/3.1/classes/class_@gdscript.html#class-gdscript-method-clamp

by (7,860 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.