How to display Stat values as part of the UI?

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
DanielCross
Newbie
Posts: 24
Joined: Sun Apr 26, 2015 9:29 pm
Contact:

How to display Stat values as part of the UI?

#1 Post by DanielCross »

Hi, I'm still getting used to ren.py and I'm trying to figure out how to show stats values(Strength, Charisma, Magic, etc) as part of UI. Just in a few boxes lined up against the top right of the screen. Is there something in the cookbook I can use as a template?

Thanks!

Xaiyeon
Newbie
Posts: 12
Joined: Thu May 14, 2015 10:47 pm
Contact:

Re: How to display Stat values as part of the UI?

#2 Post by Xaiyeon »

Hi, it depends on if you are going to use classes. I can share you my code from my game I'm currently making, but it might not make sense to you xD. I suggest you read the guide on classes and screen language and go from there! I'll share you my code as a reference. There is probably more ways to do this, but here is mine:

Screen language:

Code: Select all

# Status Menu/Screen used for Characters!


screen roystatus:    
    frame:
        xpos 20
        ypos 550
        has vbox
        text "{b}{color=#000033}Nagisuna:{/b}{/color}"
        text "{color=#000000}Personality: [Nagisuna.personality]{/color}"
        text "{color=#000000}Mood Points: [Nagisuna.mood]{/color}"        

        textbutton "Return" action Return()

init -2:
    style roystatus:
        size 18

label roystatus_label:
    call screen roystatus_screen
    return

The Code in script python:

Code: Select all

    class Player(renpy.store.object):
        def __init__(self, name, mood=0, personality=None):
            self.name=name
            self.mood = mood
            self.personality = personality
            self.startmood = 0
            
        def moodpoints(self, thechoice):
            if(thechoice == 'good'):
                self.mood += 1
            elif(thechoice == 'bad'):
                self.mood -= 2
            elif(thehoice == 'none'):
                self.mood = self.mood
                
        def showpoints(self):
            print(str(self.mood) + " points.")
        
        def status_overlay(self):
            mood = self.mood
            name = self.name
            if statusshow:
                ui.window(xpos=100, xanchor=100, ypos=100, yanchor=100, background="statoverlay.png", yfill=True, xfill=True)
                ui.vbox(xpos=100, xanchor=100, ypos=100, yanchor=100, clipping=False, spacing=12)
                ui.text(name + ": " + "%d" % mood + " mood points", size=30, color="#091a2c")
                ui.close()
                
    player = Player("Person", 100, 100) 
You could also take a look at Leon's inventory screen renpy template.
Good luck~
If people ignore others with a lack of understanding, then they are close-minded.

DanielCross
Newbie
Posts: 24
Joined: Sun Apr 26, 2015 9:29 pm
Contact:

Re: How to display Stat values as part of the UI?

#3 Post by DanielCross »

That was much easier than I thought! I'll also take a look at Leon's inventory template, thank you!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]