0 votes

I want to have a Texture progress node displaying the amount of fuel my main character has remaining. This node displays a value from 0 to 100, so to get a percentage of fuel vs maximum fuel I used this code:

$CanvasLayer/TextureProgress.value = (fuel / MAX_FUEL) * 100

However, the progress bar simply appears completely empty. I tested it and it seems to work fine with any static value or single variable, which confuses me as this equation should be a plain integer from 0 to 100. Is there any solution for this, or am I just being dumb and doing something wrong? Thanks in advance!

in Engine by (67 points)

Wich function you put this code?

1 Answer

+1 vote

This is the nature of integer division. 50 / 100 results in 0.

Change to float(fuel) / MAX_FUEL and you should be fine.

by (21,928 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.