Need help with adjustable hp

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
DewyNebula
Newbie
Posts: 15
Joined: Sun Apr 21, 2024 10:57 am
Contact:

Need help with adjustable hp

#1 Post by DewyNebula »

Hiya. I got combat working in my game, where attacks scale off other variables like strength and weapons. However, I currently need help with the health bar. While I can get the enemy to attack the player, the health bar does not update from variables, such as constitution, leaving an empty part where the increase should occur. Here is my code:

Code: Select all

# Player Battle
default player_health = player_health_func()

# Player health function = player_health()
init python:
    def player_health_func():
        return 50 + constitution + shirt_health + pant_health

screen player_hud_battle():
    vbox:
        align(0.02, 0.98)
        text "[player]"
        hbox:
            bar:
                value AnimatedValue(player_health, player_health_func(), delay=1.0)
                left_bar "/gui/bar/left.png"
                right_bar "/gui/bar/right.png"
                maximum(525, 38)

$ player_health -= burglar_attack

User avatar
jeffster
Miko-Class Veteran
Posts: 888
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Need help with adjustable hp

#2 Post by jeffster »

DewyNebula wrote: Tue May 14, 2024 4:24 pm Hiya. I got combat working in my game, where attacks scale off other variables like strength and weapons. However, I currently need help with the health bar. While I can get the enemy to attack the player, the health bar does not update from variables, such as constitution, leaving an empty part where the increase should occur. Here is my code:
I can't say what's wrong as I don't see the part of code where you show the screen and change the value. If the code is correct, then maybe try to update the screen using

renpy.restart_interaction()

?

PS. Judging solely from the code you posted, it's the range (the bar length) that changes with variable `constitution`, not the actual player's health.
https://renpy.org/doc/html/screen_actio ... matedValue
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

DewyNebula
Newbie
Posts: 15
Joined: Sun Apr 21, 2024 10:57 am
Contact:

Re: Need help with adjustable hp

#3 Post by DewyNebula »

jeffster wrote: Wed May 15, 2024 4:42 pm
DewyNebula wrote: Tue May 14, 2024 4:24 pm Hiya. I got combat working in my game, where attacks scale off other variables like strength and weapons. However, I currently need help with the health bar. While I can get the enemy to attack the player, the health bar does not update from variables, such as constitution, leaving an empty part where the increase should occur. Here is my code:
I can't say what's wrong as I don't see the part of code where you show the screen and change the value. If the code is correct, then maybe try to update the screen using

renpy.restart_interaction()

?

PS. Judging solely from the code you posted, it's the range (the bar length) that changes with variable `constitution`, not the actual player's health.
https://renpy.org/doc/html/screen_actio ... matedValue
Oh, sorry, my mistake. Here is all the other information (Also edited previously posted code):

Code: Select all

# player_stats file
default player_health = player_health_func()
init python:
    def player_health_func():
        return 50 + constitution + patch_constitution
# player_hud_battle file
screen player_hud_battle():
    vbar:
        value AnimatedValue(player_health, player_health_func(), delay=1.0)
        align(0.005, 0.87)
        maximum(150, 150)
        top_bar "bar-health-top"
        bottom_bar "bar-health-bottom"
# enemy_burglar_battle file
while (player_health >= 0) and (burglar_health > 0):       
        elif burglar_health >= 40:
            $ player_health -= burglar_attack
            $ random_dialogue = renpy.random.choice(burglar_attack_dialogue)
            "[random_dialogue]"

User avatar
jeffster
Miko-Class Veteran
Posts: 888
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Need help with adjustable hp

#4 Post by jeffster »

DewyNebula wrote: Wed May 15, 2024 6:57 pm

Code: Select all

# player_stats file
default player_health = player_health_func()
init python:
    def player_health_func():
        return 50 + constitution + patch_constitution
# player_hud_battle file
screen player_hud_battle():
    vbar:
        value AnimatedValue(player_health, player_health_func(), delay=1.0)
        align(0.005, 0.87)
        maximum(150, 150)
        top_bar "bar-health-top"
        bottom_bar "bar-health-bottom"
# enemy_burglar_battle file
while (player_health >= 0) and (burglar_health > 0):       
        elif burglar_health >= 40:
            $ player_health -= burglar_attack
            $ random_dialogue = renpy.random.choice(burglar_attack_dialogue)
            "[random_dialogue]"
When I test this code it works alright. What is the problem again?

PS. If you increase constitution, the bar maximum increases, not the current health. The bar's height in pixels is fixed, so it looks like the empty part of the bar grows. E.g. health was 20, the bar range was 100. You add 50 to constitution, and the bar range becomes 150. The health is still 20, so before it looked like 1/5th of the bar filled (20/100), now it looks like 20/150 of the bar is filled.
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

DewyNebula
Newbie
Posts: 15
Joined: Sun Apr 21, 2024 10:57 am
Contact:

Re: Need help with adjustable hp

#5 Post by DewyNebula »

jeffster wrote: Wed May 15, 2024 11:13 pm
DewyNebula wrote: Wed May 15, 2024 6:57 pm

Code: Select all

# player_stats file
default player_health = player_health_func()
init python:
    def player_health_func():
        return 50 + constitution + patch_constitution
# player_hud_battle file
screen player_hud_battle():
    vbar:
        value AnimatedValue(player_health, player_health_func(), delay=1.0)
        align(0.005, 0.87)
        maximum(150, 150)
        top_bar "bar-health-top"
        bottom_bar "bar-health-bottom"
# enemy_burglar_battle file
while (player_health >= 0) and (burglar_health > 0):       
        elif burglar_health >= 40:
            $ player_health -= burglar_attack
            $ random_dialogue = renpy.random.choice(burglar_attack_dialogue)
            "[random_dialogue]"
When I test this code it works alright. What is the problem again?

PS. If you increase constitution, the bar maximum increases, not the current health. The bar's height in pixels is fixed, so it looks like the empty part of the bar grows. E.g. health was 20, the bar range was 100. You add 50 to constitution, and the bar range becomes 150. The health is still 20, so before it looked like 1/5th of the bar filled (20/100), now it looks like 20/150 of the bar is filled.
Oh, that makes sense. When I set the current health to equal the health function, I thought it would remain full if the health function increased. That was my mistake. Thank you for the help!

Post Reply

Who is online

Users browsing this forum: Google [Bot]