Dynamic Statusbar

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
pew pew
Newbie
Posts: 6
Joined: Sun Jan 07, 2018 3:51 pm
Contact:

Dynamic Statusbar

#1 Post by pew pew » Tue Jan 09, 2018 6:41 pm

Hello there,

I currently have a problem which i can't figure out.
I want a dynamic status bar on top. My Issue is that I don't know how to call a function and in general have no idea how a function is composed.
I'd like to be it a function, since I belive this way is the faster and cleaner approach. Feel free to prove me wrong.

My Statusbar has a variable "A", which changes Value during choice making. ( $ A += 1 )
What I want is that after choice which changes "A" a function runs and checks:

Code: Select all

if A <= 5:
	B = "Bad"
if A <= 10:
	B = "Neutral"
else:
	B = "Good"
And "B" has to be displayed in the Statusbar like "B = Neutral"

Here is my screen code (Which makes probably no sense.. to me neither. Renpy doesn't complain tho.):

Code: Select all

init python:
    def fc_al(al):
        self.hero_align = al
        
        if al == 0:
            self.hero_align = "Neutral"
        if al == 1:
            self.hero_align = "Bad"
        else:
            self.hero_align = "Good"
   
screen Statusbar:
    style_prefix "Stat"
    frame:
        xalign 1 ypos 0
        hbox:
            text "A = [al]"
            text "B = [hero_align]"
It works for "A" which changes it's value after making choices. "B" however, has just an empty space next to the equal symbol.

Btw.: This Forums Thread search gives me always 504 no idea if thats just on my end or the forum itself.

User avatar
erickcire95
Regular
Posts: 33
Joined: Tue Dec 26, 2017 7:38 pm
Contact:

Re: Dynamic Statusbar

#2 Post by erickcire95 » Thu Jan 11, 2018 1:31 am

I think the function is not really necessary here, it's a lot simpler to just use a conditional in the screen, this here works as you want. It works based on the value of the variable "al"

Code: Select all

screen Statusbar:
    style_prefix "Stat"
    frame:
        xalign 1 ypos 0
        vbox:
            text "A = [al]"
            if al <= 5:
                text "B = Bad"
            elif al <= 10:
                text "B = Neutral"
            else:
                text "B = Good"

pew pew
Newbie
Posts: 6
Joined: Sun Jan 07, 2018 3:51 pm
Contact:

Re: Dynamic Statusbar

#3 Post by pew pew » Thu Jan 11, 2018 12:13 pm

Works like a charm and is indeed way simpler as I thought of. Thank you!!

Post Reply

Who is online

Users browsing this forum: Google [Bot], Yjga125