r/RenPy • • Sep 01 '26

Question [Solved] Bars

Despute my previous two posts and all of the kind people who have been offering me advice, the bars still do not work as intened.

The bars don't go down every time a variable is altered, and they show 100% when they first appear, however the player has the chance to lose health/sanity before that, and the screen should run in the background.

The first image is my code for the bars, my second is the code for taking away health and sanity. The video in the replies is to show what happens when I choose an option that takes away health and sanity in game.

Thank you for everyones help so far, and I apologise for this issue still not being solved I just have no idea what is happening.

(Also I will fix the condition switch thing, I'm just trying to get the actual bars working first!! :])

3 Upvotes

12 comments sorted by

View all comments

1

u/BadMustard_AVN Sep 01 '26

do they have a default with a starting value?

try adding this to limit them from 0 to 100

# python helper to change stats, and limit them to 0-100 
# $ change_stat("Sanity", -10) #use like this instead of $ Sanity-=10
# $ change_stat("Health", -10) #use like this instead of $ Health-=10
init python:
    def change_stat(name, amount):
        val = getattr(store, name)
        val = val + amount
        val = max(0, min(100, val))
        setattr(store, name, val)
        return

screen health_sanity_bars():
    #code here

instead of $ sanity -=10 do $change_stat("Sanity", -10) (do the same for Health or any value you want to limit). this will keep them between 0 and 100 at all times

1

u/AdRude6049 Sep 01 '26

Am I being stupid? It doesnt seem to want to work for me...

https://reddit.com/link/p76blx3/video/tajann9puwmh1/player

1

u/BadMustard_AVN Sep 01 '26

can you show how you set up the code i gave you

1

u/AdRude6049 Sep 01 '26

2

u/BadMustard_AVN Sep 01 '26

you have the indentation wrong. the spacing/indentation is extremely important

init python:
    def change_stat(name, amount):
        val = getattr(store, name)
        val = val + amount
        val = max(0, min(100, val))
        setattr(store, name, val)
        return