Page 1 of 1

HP bar help

Posted: Fri Dec 09, 2016 7:30 pm
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

Re: HP bar help

Posted: Fri Dec 09, 2016 8:48 pm
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.

Re: HP bar help

Posted: Fri Dec 09, 2016 10:13 pm
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

Re: HP bar help

Posted: Fri Dec 09, 2016 11:11 pm
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.

Re: HP bar help

Posted: Sat Dec 10, 2016 5:08 am
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.

Re: HP bar help

Posted: Sat Dec 10, 2016 10:20 am
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.

Re: HP bar help

Posted: Sat Dec 10, 2016 6:20 pm
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?

Re: HP bar help

Posted: Sat Dec 10, 2016 10:57 pm
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

Re: HP bar help

Posted: Sun Dec 11, 2016 5:25 am
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.

Re: HP bar help

Posted: Sun Dec 11, 2016 5:10 pm
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.

Re: HP bar help

Posted: Sun Dec 11, 2016 8:44 pm
by JayBlue
Indeed. :)

Thanks for helping me out guys.