Godot Version
Godot 4
Question
I am trying to make a progressbar in godot 4 that counts down, and everything works except apparently seeming to update the progress bar… (I mean that I added a bunch of print() things everywhere and they all trigger, except the progress bar does not update as the timer ticks down"
basically, there is a timer and whenever the timer runs out it reduces the variable life by one, and I want the progress bar to reflect that. I tried puttting it in both the _process(delta) as well as the timeout function. also I changed the maximum on the progress bar to 10
is there something in a menu in the inspector I could be missing?
var life = 10
[@ sign]export var ResourceType : St
func _ready():
var timer = get_node(“Timer”)
timer.timeout.connect(_on_timer_timeout)
producing = true
life = 10
func _on_timer_timeout():
if producing && GameManager.CurrentState == GameManager.State.Play:
for area in $ProduceArea2D.get_overlapping_areas():
if ResourceType == “wood” && “ForestArea” in area.name:
GameManager.wood += 5
lifeAssess()
life -= 1
$Control/ProgressBar.value = life
func lifeAssess():
if life > 0:
return
else:
producing = false
Thanks so much in advance for any help!
need to check the indentation of this:
cant tell what the if has or not
Hi, im so sorry, im posting on behalf of a friend so I totally forgot I had to reformat it! I just took a screenshot of what he sent me relating to your reply.
so something should be making it never actually enter the line of code of life-=1
this line
if producing && GameManager.CurrentState == GameManager.State.Play:
since we know producing is true, then the
GameManager.CurrentState == GameManager.State.Play
is never true, hence why it never actually have a chance to remove a life
show the line where GameManager.CurrentState actually changed
His response: The thing is, I added a bunch of print(life) functions everywhere, the life value is decreasing, for some reason the $Control/ProgressBar. value is not updating despite that
i see try change to:
$Control/ProgressBar.set_value(float(life))
That doesn’t see to work either-
a thing I’ve noticed is that even if I set the value in inspector to not be 10, when running the code the progressbar is full (and stays full). But in debug menu the life is still decreasing…
then it’s a weird one, because progressbar value is very easy to modify. just modify the value property.
can you show your progressbar inspector properties like this?

is this the settings you have for the progress bar?
heres the screenshot- thank you so much for being so helpful!
are you accessing the correct progressbar? can you show your scene tree?

This is the scene tree, and I am not getting anyhting in the debugger, and this is the only progressBar Ive used in the code.
you are sure that the life value is actually changing?
because the progressbar value should already be changing too when the life value is changed
try
print($Control/ProgressBar.value)
along with print(life)
Wait, that is weird… the value of the bar is changing but it is not visible in the game… maybe it could be some issue with scaling/formatting and it decided to always be the color/texture assigned to the bar as full
You should check the filling color of the progress bar, maybe it’s transparent and that’s why you never seem the bar to change. You can also activate the option “show percentage just for testing purposes”

You can use a theme override just to test this, here i use a StyleBoxFlat with a white background and a Fill with a green background. Also if you are using a theme you should check those settings in the Theme editor.
After clicking show percentage, the percentage still doesnt show up, Maybe I scaled it wrong? or something… the themes arent transparent though

even if it’s small, the text should always show
it doesnt show in your place?
wait so your progressbar have styles?
It didnt, for some reason. I deleted the progress bar, remade it (basically just resizing and recoloring, but at this point I do not know the problem)
now the percent shows, but it still does not chagne when tested
I did theme override → styles, but just the style box flat and did colors
the prints for both life and the value also the same or the value for progressbar stays at 10?
the prints for life and value decrease as they should, but for some reason it is not reflected in the progress bar