Ren'Py Status bar

Mad King

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,903
Hi mates,

I am having trouble figuring this out.
For the game, I develop I have status bars that don't show any progress when the player gets points. I did some tests and if a player will receive 40 or more points, it will show the progress in the bar but if the player points are under 40, the bar will still be empty.

Le code de vie:

status_setup:
Code:
init -5 python:
    style.my_barlove = Style(style.default)
    style.my_barlove.left_bar = Frame ("gui/love_full.png", 0, 0)
    style.my_barlove.right_bar = Frame ("gui/love.png", 0, 0)
    style.my_barlove.xmaximum = 680 # bar width
    style.my_barlove.ymaximum = 214 # bar height
    style.my_barlove.xalign= 1.0
    style.my_barlove.yalign= 1.0

init -6 python:
    style.my_barlust = Style(style.default)
    style.my_barlust.left_bar = Frame("gui/lust.png", 0, 0)
    style.my_barlust.right_bar = Frame("gui/lust_empty.png", 0, 0)
    style.my_barlust.xmaximum = 680 # bar width
    style.my_barlust.ymaximum = 214 # bar height
    style.my_barlust.xalign= 1.0
    style.my_barlust.yalign= 1.0
script.rpy
Code:
# here I set the variable for a character, to zero
$ mot_love = 0
$mot_lust = 0
screens.rpy:

Code:
screen  mot:
        modal True
        frame:
           background "bg.jpg"
        bar:
             style "my_barlove"
             value mot_love
             range 100
             yalign 0.1
             xalign 0.0


        bar:
             style "my_barlust"
             value mot_lust
             range 100
             yalign 0.45
             xalign 0.0
What can I do?

Thank you!
 

Rich

Old Fart
Modder
Respected User
Donor
Game Developer
Jun 25, 2017
2,452
6,908
The problem is with your styles. You're defining your styles based on "default". If you base them on "bar" instead, I think things may work as you expect. At least, when I make that change, the bars now appear on the screen.
 

Mad King

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,903
So instead of
Code:
 style.my_barlove = Style(style.defaul)
# I should replace it with   
style.my_barlove = Style(style.bar)
?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,103
14,755
I am having trouble figuring this out.
There's many problems :
  • You don't need Python to define a style ;
  • Like @Rich said, you should have based your style on bar ;
  • You could have take benefit from style inheritance ;
  • You define xalign and yalign in the style, to overwrite them in the screen ;
  • Like it's bars, I assume that the screen is always show, so the Modal True must not be here ;
  • It's way better to define the variable with the default statement.

Python:
#  Defined the common style for both bars. 
# Made it inherit form the default bar style.
style my_bar is bar:
    xmaximum 680
    ymaximum 214
    xalign 0.0

#  Inherit from the common style, only had what
# differs from a bar to another.
style my_barlove is my_bar:
    left_bar Frame ("gui/love_full.png", 0, 0)
    right_bar Frame ("gui/love.png", 0, 0)
    yalign 0.1

style my_barlust is my_bar:
    left_bar Frame ("gui/lust_full.png", 0, 0)
    # Constancy issue - "love.png" Vs "lust_empty.png"
    right_bar Frame ("gui/lust_empty.png", 0, 0)
    yalign 0.45

#  For future compatibility.
default mot_love = 0
default mot_lust = 0

screen mot:
#  Will prevent the player to effectively play the 
# game if it's a part of the User Interface.
#        modal True
        frame:
           background "bg.jpg"
        bar:
             style "my_barlove"
             value mot_love
             range 100
#  Defined in the style
#             yalign 0.1
#             xalign 0.0

        bar:
             style "my_barlust"
             value mot_lust
             range 100
#  Defined in the style
#             yalign 0.45
#             xalign 0.0
Like this it works.
 

Mad King

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,903
Thank you all for the reply,

@anne O'nymous
There is a status page, for each character. The status bar for each is positioned differently and so I used a custom style and modal true.

I found the problem. It wasn't because of the code it was because of the graphic of the bar.
1554918696587.png

In the example above the bar somehow starts to fill from the beginning of the bar png and in my case, it is from the card and not from the bar. Even if it is not visible, the fill was actually starting to fill from behind the card and not from where the empty bar starts.
1554918867005.png
The solution will be to redesign the bars so the image should start at the beginning of the bar.
I found this as I had a hunch and I eliminated the card and cropped the image to begin where the bar starts

Highway to hell :))
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,103
14,755
The status bar for each is positioned differently and so I used a custom style and modal true.
Then put the xalign/yalign in the screen, not in the style.


The solution will be to redesign the bars [...]
Why ? The problem never was the bars, it's the screen :
Python:
style my_bar is bar:
    xmaximum 680 # bar width
    ymaximum 214 # bar height
    yalign  0.5

style my_barlove is my_bar:
    left_bar Frame ("gui/love_full.png", 0, 0)
    right_bar Frame ("gui/love.png", 0, 0)

style my_barlust is my_bar:
    left_bar Frame ("gui/lust_full.png", 0, 0)
    right_bar Frame ("gui/lust_empty.png", 0, 0)

default mot_love = 0
default mot_lust = 0

screen mot:
        modal True
        frame:
            background "bg.jpg"

        #  Pretty please Ren'py, arrange this vertically,
        # one below the previous.
        vbox:
            #  Pretty please Ren'py, arrange this horizontally,
            # one at the right of the previous.
            hbox:
                # Display the card - I use random names.
                add "card_love.jpg"
                # Add a 5 pixel space
                null width 5
                # And now display the bar.
                bar:
                    style "my_barlove"
                    value mot_love
                    range 100
                    #  No, seriously, you do NOT need yalign.
                    # The /hbox/ act as container, try and see.

            hbox:
                add "card_lust.jpg"
                null width 5
                bar:
                    style "my_barlust"
                    value mot_lust
                    range 100
But honestly this is better :
Python:
style my_bar is bar:
    xmaximum 110 # width of the card
    ymaximum 189 # height of the card
    right_bar Solid( "#000000A0" )
    left_bar Solid( "#00000000" )

default mot_love = 0
default mot_lust = 0

screen mot:
        modal True
        frame:
            background "bg.jpg"

        frame:
            style "empty"
            xalign 0.0
            ypos 0
            add "card_love.jpg"
            bar:
                style "my_bar"
                value mot_love
                range 100

        frame:
            style "empty"
            xalign 0.0
            ypos 200    # depend of the height of the card
            add "card_lust.jpg"
            bar:
                style "my_bar"
                value mot_lust
                range 100
 

Mad King

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,903
Sorry for the late reply.

I used the code:

Code:
style my_bar is bar:
    xmaximum 110 # width of the card
    ymaximum 189 # height of the card
    right_bar Solid( "#000000A0" )
    left_bar Solid( "#00000000" )

default mot_love = 0
default mot_lust = 0

screen mot:
        modal True
        frame:
            background "bg.jpg"

        frame:
            style "empty"
            xalign 0.0
            ypos 0
            add "card_love.jpg"
            bar:
                style "my_bar"
                value mot_love
                range 100

        frame:
            style "empty"
            xalign 0.0
            ypos 200    # depend of the height of the card
            add "card_lust.jpg"
            bar:
                style "my_bar"
                value mot_lust
                range 100
And it worked. Thank both of you for the help you gave with this issue. I am in your debt.
 
  • Like
Reactions: anne O'nymous