0 votes

My code is suppossed to have a progressbar that will show you how full your storage is, but instead it says that the bits / capacity * 100 is 0, and only changes it to 100% once its at max, and i have no idea why. The code in question:

func _process(delta):
$Label.text = str(Bits)
Second += delta
if Bits > 0:
    $ProgressBar.value = round(Bits / Capacity) * 100
    print(round(Bits / Capacity) * 100)
if Second > 1:
    Second = 0.001
    if Bits < Capacity and Bits + Spark_Gens < Capacity:
        Bits = Bits + Spark_Gens
        if Spark_Gens > 0:
                $AudioStreamPlayer.play()
    else:
        Bits = Capacity
Godot version 3.4 i think
in Engine by (20 points)

1 Answer

0 votes

If Bits and Capacity are integers, then this makes sense.

var a = 1
var b = 2
var c = a / b  # c is 0, because of integer division

If you convert one or both to floats, your result will be a float, ex: float(Bits)

by (21,714 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 Frequently asked questions and 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 [email protected] with your username.