TextureProgressBar showing incorrect amount

Godot Version

Godot 4.2.1.stable

Question

My TextureProgressBar isn’t showing the correct amount of “rage” a stat in my game. When I have 100 rage I can superjump, but the bars max is 100 and when it is full I still can’t do the jump.

Edit - 1:
I tested it and it also shows no rage even when I have some. And the bar shows max at 74 rage.

Share the code to see the problem.

extends TextureProgressBar

@export var player: CharacterBody2D

func _ready():
	player.rageChanged.connect(update)
	update()


func update():
	value = player.rage * 100 / player.maxRage


Thats the code for the bar itself, if you need anything else just tell me
you probably need the regen code to:

func _process(delta):
	diff += delta
	if diff >= 0.1:
		rage += 1
		diff = 0
		rageChanged.emit()

I’m warning you that I’m not an expert in this engine, but when you call “connect()” shouldn’t it be “_process(delta)” for the texture to be updated?

I’m not an expert either but I’m pretty sure the connect is to connect the signals, allow the bar to know it needs to update. The bar updates just it doesn’t display correctly

to clamp it to max rage, just use

value=clamp(player.rage*100.0,0,player.maxRage)
1 Like

I put it in the progressbar script and it says “unidentified identifier in class body”

Edit 1- I put it in the update func and now the bar is always max

so the player.rage doesnt need that 100.0 multiplication
just

value=clamp(player.rage,0.0,player.maxRage)

So I replace the value with that instead of adding it?

Edit- Sorry for asking so many questions also, I’m just really new to coding

yes, change it here:

sorry to inform you but it still shows the wrong amount

show your update code again with modified value with clamp

it should be pretty simple to clamp a value, nothing special with it
either you wrote the update wrong or the player rage never changed

extends TextureProgressBar

@export var player: CharacterBody2D

func _ready():
	player.rageChanged.connect(update)
	update()


func update():
	value=clamp(player.rage,0.0,player.maxRage)

if you add

print(player.rage)

before the clamp, is the rage updating or not?
what the print said?

sorry for being a wee little late but yeah I gave up for a little, but the bar doesnt show any progress until 30ish (I tested your idea)

It could help you.

var reloj: Tween
    
  func _ready():
     $ProgressBar.max_value = 100.0
     $ProgressBar.value = 0.0

  func tweenAnimation(methodForExecute: Callable, initialValue: int, newValue: int):
	 if reloj:
		reloj.kill()
	
	 reloj = create_tween().set_parallel(true)
	 reloj.set_process_mode(Tween.TWEEN_PROCESS_PHYSICS)
	 reloj.set_trans(Tween.TRANS_LINEAR)
	 reloj.set_ease(Tween.EASE_IN)
	
	 reloj.tween_method(methodForExecute, initialValue, newValue, 0.5)
	 reloj.play()

    func changingValue(newValue: int):
	   $ProgressBar.value = newValue

    func visualModification(newValue: int = 0):
	  tweenAnimation(changingValue, $ProgressBar.value, newValue)

Where would I put this in the script?

for example

func _ready():
 visualModification(90)  # 90% 0-100

You could use it where you wish. Remember to change

$ProgressBar # for the name of  your node.