|
|
|
|
Reply From: |
jgodfrey |
Generally, the code you show looks reasonable. Some things to check
- Is the code being executed?
- Does
healthBar
contain a valid reference to your ProgressBar
control?
- What is the value of
health
?
- What are
min_value
and max_value
properties set to on the ProgressBar
?
- Does changing the
value
property in the inspector change the progress indicator as expected?
1: Yes, I tested and the code is being executed
2: Yes, when the code was run I included print (healthBar.name)
, which responded correctly
3: The value of health
is being correctly updated, I tested with print
4: healthBar.min_value
is set in the inspector to 0, and healthBar.max_value
is set in the code. I could not test either of these.
5: Yes
JIYProgrammer | 2023-05-17 00:42
Other things to check, what is the step of your progress bar? If it’s not an integer you might have to make sure you cast health
to a float. Might also help if you shared some of your code. If percent_visible is set to true, do the numbers update at runtime?
Tom Mertz | 2023-05-17 00:59
healthBar.step
is 0.01, and the damage is added as a float.
My code is very divided, would I need to upload all of it? I tried to compartmentalize and make it modular but I only succeeded in adding roots from one script to all others. Also, would you want my scene and prefab trees?
healthBar.percent_visible
is true
, but nothing updates in the runtime, only from the inspector and editor.
JIYProgrammer | 2023-05-17 01:45
Very strange, really the more info you can give the better we could troubleshooting. Compartmentalized is generally a good thing! I think the code around setting up the progress bar, what signals or methods change it’s value etc would be a good start. Dumb second question, if you just set in your code instead of healthBar.value = health
make it healthBar.value = 100.0
or whatever your max value is, does that do anything?
Tom Mertz | 2023-05-17 01:59
Also, if the project itself is available online, sharing it would be an easy way to get additional input. Really, this is likely something quite simple, but it’s difficult to diagnose all of the possibilities via a forum post…
jgodfrey | 2023-05-17 02:07
I wouldn’t notice because it’s already stuck at 100%. might try setting it to zero, though.
JIYProgrammer | 2023-05-17 02:07
You never said what your health
value is. Is it possibly greater than 100?
jgodfrey | 2023-05-17 02:11
How would I share my project?
JIYProgrammer | 2023-05-17 02:17
Yes, it starts greater than 100, but healthBar.max_value
is also greater than 100. Also, I don’t see any change when health
goes to less than 100.
JIYProgrammer | 2023-05-17 02:19
If it happens to be a public repo in github (for example), you could just share the url. Otherwise, you could zip up the project’s entire folder structure, upload it to a cloud storage service (dropbox, google drive, onedrive, …) and share a link.
jgodfrey | 2023-05-17 02:20
Yes, it starts greater than 100, but healthBar.max_value is also greater than 100.
Ah, I thought max_value
was 100 here, but I see that’s not the case. So, your health
value isn’t greater than max_value
I guess…
jgodfrey | 2023-05-17 02:28
ok, did further testing, apparently the progress bar was only showing when health
was under 100. My bad, I thought I’d tested that. I don’t think I have a solution yet, but at least now I know what I need to work on.
JIYProgrammer | 2023-05-17 02:37
Glad you have something to look at. You mentioned that max_value
was being set in code. Are you sure that’s working? If not, max_value
will default to 100 and any value
>= 100 will cause the bar to be completely full - which sounds like what you’re describing.
jgodfrey | 2023-05-17 02:40