HP bar help

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
User avatar
JayBlue
Regular
Posts: 86
Joined: Fri Aug 26, 2016 7:10 pm
Location: Space
Contact:

HP bar help

#1 Post by JayBlue »

I need to be able to define the max hp value with this variable --> PartySlot_1_maxHP.
but it doesn't work

Code: Select all

        bar value VariableValue("PartySlot_1_HP", PartySlot_1_maxHP):
            yalign 0.01
            xpos 90
            xmaximum 348
            ymaximum 20
            left_bar Frame("gui/Bar_HP.png", 348, 20)
            right_bar Frame("gui/Bar.png", 348, 20)
            #left_gutter 0
            #right_gutter 0
            thumb None
            thumb_shadow None    


help plz
If an Owl hoots in a forest, does it make a sound?

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: HP bar help

#2 Post by papiersam »

Should just be

Code: Select all

    bar: 
        range PartySlot_1_maxHP
        value PartySlot_1_current
        yalign 0.01
        xpos 90
        xmaximum 348
        ymaximum 20
        left_bar Frame("gui/Bar_HP.png", 348, 20)
        right_bar Frame("gui/Bar.png", 348, 20)
        #left_gutter 0
        #right_gutter 0
        thumb None
        thumb_shadow None    
Notice the range+value; range is basically the maximum value of the bar, while value is the amount of the bar that will be filled. That's why I set range to maxHP and value to currentHP.

Hope this helps.

User avatar
JayBlue
Regular
Posts: 86
Joined: Fri Aug 26, 2016 7:10 pm
Location: Space
Contact:

Re: HP bar help

#3 Post by JayBlue »

Okay. I changed up the code. The bar is showing up on screen, but HP bar isn't decreasing when the character takes damage. I set up a label to tell me if the variable's value is changing and is says that it is, but the HP bar doesn't show that.

This is how the code looks now

Code: Select all

        bar:
            range PartySlot_1_maxHP
            value PartySlot_1_current
            yalign 0.01
            xpos 90
            xmaximum 348
            ymaximum 20
            left_bar Frame("gui/Bar_HP.png", 348, 20)
            right_bar Frame("gui/Bar.png", 348, 20)
            #left_gutter 0
            #right_gutter 0
            thumb None
            thumb_shadow None    
      
        label _("HP [PartySlot_1_current]/[PartySlot_1_maxHP]") xpos 90 ypos 17 
Sorry, still need help
If an Owl hoots in a forest, does it make a sound?

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: HP bar help

#4 Post by papiersam »

Everything looks right to me. Are you sure you're decreasing PartySlot_1_current? Could I see how you're implementing it?

Edit: the label is saying it's working, so you probably need to use $renpy.refresh_interaction(). I've tried it out here

Code: Select all

screen a:        
        
        textbutton "Attack" action SetVariable("PartySlot_1_current", PartySlot_1_current - 15)
        bar:
            range PartySlot_1_maxHP
            value PartySlot_1_current
            yalign 0.01
            xpos 90
            xmaximum 348
            ymaximum 20
         #   left_bar Frame("gui/Bar_HP.png", 348, 20)
          #  right_bar Frame("gui/Bar.png", 348, 20)
            #left_gutter 0
            #right_gutter 0
            thumb None
            thumb_shadow None    
      
        label _("HP [PartySlot_1_current]/[PartySlot_1_maxHP]") xpos 90 ypos 17 
        
        
label start:
    
    $PartySlot_1_maxHP=125
    $PartySlot_1_current=120
    show screen a
    
    "Test"
    
    $PartySlot_1_current -= 15
    
    "Change?"
    

    hide screen a 
    
    call screen a
    
    "Change?"
    
And it seems to be updating fine. If there's still an error, post up the code so we can help.

User avatar
JayBlue
Regular
Posts: 86
Joined: Fri Aug 26, 2016 7:10 pm
Location: Space
Contact:

Re: HP bar help

#5 Post by JayBlue »

Here's how I'm implementing the code so far

Code: Select all

label start:
    
    scene bg black with Dissolve(1)
    "Starting game"

    menu:
        "Test Inventory":
            "Testing Inventory"
            jump Inventorytest
        "Test HP":
            "Testing HP"
            $ InBattle = True
            jump HPtest

label HPtest:
    while InBattle is True:
        call screen HPbartest 
        $ PartySlot_1_current -= 37
    return

screen HPbartest():    
    bar:
        range PartySlot_1_maxHP
        value PartySlot_1_current
        yalign 0.01
        xpos 90
        xmaximum 348
        ymaximum 20
        left_bar Frame("gui/Bar_HP.png", 348, 20)
        right_bar Frame("gui/Bar.png", 348, 20)
        #left_gutter 0
        #right_gutter 0
        thumb None
        thumb_shadow None    
    label _("HP [PartySlot_1_current]/[PartySlot_1_maxHP]") xpos 90 ypos 17 
    imagebutton auto "gui/Button_return_%s.png" xpos 25 ypos 530 focus_mask True action Return()
and here's the declared variables I'm using

Code: Select all

init:
    define MC = Character('MC', color="#c8c8ff", show_two_window=True)
    $ InBattle = False
    $ PartySlot_1_maxHP = 100
    $ PartySlot_1_current = 100
What I end up seeing is the HP on the label updating every time I go through the while statement and the HP bar doesn't update. The HP bar always looks full.
If an Owl hoots in a forest, does it make a sound?

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: HP bar help

#6 Post by papiersam »

I tested the code you posted, and it's definitely updating for me. Try testing it without the right_bar and left_bar arguments, maybe it's the images you've chosen that make it look like it's not updating. If not, try deleting persistent data or testing it in a new project.

User avatar
JayBlue
Regular
Posts: 86
Joined: Fri Aug 26, 2016 7:10 pm
Location: Space
Contact:

Re: HP bar help

#7 Post by JayBlue »

Tried everything. Through the process of elimination I figured why it wasn't working.

It was the parentheses in --> screen HPbartest():

Now the code looks like this

Code: Select all

screen HPbartest:   
    bar:
        range PartySlot_1_maxHP
        value PartySlot_1_current
        yalign 0.01
        xpos 90
        xmaximum 348
        ymaximum 20
        left_bar Frame("gui/Bar_HP.png", 348, 20)
        right_bar Frame("gui/Bar.png", 348, 20)
        #left_gutter 0
        #right_gutter 0
        thumb None
        thumb_shadow None   
    label _("HP [PartySlot_1_current]/[PartySlot_1_maxHP]") xpos 90 ypos 17
    imagebutton auto "gui/Button_return_%s.png" xpos 25 ypos 530 focus_mask True action Return()
For some reason it didn't let the bar update. Not sure why that was happening, but then again, I don't know what the parentheses are supposed to used for.

Thank you for helping me out. With any luck, I should be announcing a game in the next two months :)

btw, I don't suppose you know how to flip the health bars to make them decrease from left to right instead of right to left?
If an Owl hoots in a forest, does it make a sound?

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: HP bar help

#8 Post by xavimat »

- The parenthesis tell Ren'Py to use SL2 (Screen Language 2), instead of the older SL. It should be used always. Maybe you have found a bug.

- To flip a bar, I use a transform:

Code: Select all

screen test():
    bar range 100 value 35 xysize (200, 20) at flipped

transform flipped:
    xzoom -1.0
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
JayBlue
Regular
Posts: 86
Joined: Fri Aug 26, 2016 7:10 pm
Location: Space
Contact:

Re: HP bar help

#9 Post by JayBlue »

I see. Wow, I didn't expect it to be a bug. All this time I thought I was just an idiot :)

Bar is now flipped, thx.
If an Owl hoots in a forest, does it make a sound?

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: HP bar help

#10 Post by papiersam »

Maybe you have found a bug.
Maybe. Except that it worked perfectly when I tested the exact code given. But anyways, as long as it's fixed.

User avatar
JayBlue
Regular
Posts: 86
Joined: Fri Aug 26, 2016 7:10 pm
Location: Space
Contact:

Re: HP bar help

#11 Post by JayBlue »

Indeed. :)

Thanks for helping me out guys.
If an Owl hoots in a forest, does it make a sound?

Post Reply

Who is online

Users browsing this forum: Semrush [Bot]