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!

asked May 4 in Projects by redstonecreeper8 (21 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.

answered May 4 by kidscancode (17,702 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.