How can I hide a Progress Bar in the beginning and have it show when the item is picked up

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By stella3321

Im trying to have the progress bar only show up when an item is picked up by the player, my issue is that the progress bar just doesn’t show up on the screen at all, even after the item is picked up.
Its visible if I take the self.hide() and out, so the issue is with those specific lines of code.
I’ve also tried self.visible = false and self.visible = true instead but same issue
any help is appreciated

`extends CanvasLayer

var Items = 0

func _ready():
$Itemprogress/itembar.value = Items

func _on_item_pick_up():
Items = Items + 1

By the way, to format code over multiple lines, don’t use the ‘`’ symbol, use 4 spaces at the start of a line (and an additional 4 space for each indent) to format many lines of code

godot_dev_ | 2023-05-29 13:58

:bust_in_silhouette: Reply From: godot_dev_

The bug lies in you onitempickup function. The first line of the function will display the progress bar by calling, however, your function then calls the _ready function, which calls the self.hide() function.

Removing the _ready call in the onitempickup function will solve the bug

But if I dont have the _ready then the bar will not show any ‘progress’. Like, it wont show that an item has been picked up. Is there a way for me to have to bar hidden at the beginning and then show up when an item has been picked up without removing _ready?

stella3321 | 2023-05-29 20:48

In my opinion it’s bad practice to call _ready from other functions, since your code could get messy. The engine calls _ready for you when the scene enters the scene tree I beleive, so you should try and design your logic around that.

In any case, I think removing _ready and replacing it with $Itemprogress/itembar.value = Items in your onitempickup function should do the trick

godot_dev_ | 2023-05-29 22:13

Thank you so much! That Worked!

stella3321 | 2023-05-30 14:23