Character Stats Question [SOLVED]

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
User avatar
Pink_Juicy
Newbie
Posts: 21
Joined: Tue Feb 09, 2021 4:09 pm
Contact:

Character Stats Question [SOLVED]

#1 Post by Pink_Juicy » Sun Aug 14, 2022 5:55 pm

Is it possible to be able to code something like the attachment below? Sort of like those games where in the beginning you can customize the character's stats :D
Attachments
character stats.png
Last edited by Pink_Juicy on Sun Aug 14, 2022 6:59 pm, edited 1 time in total.

User avatar
laure44
Regular
Posts: 63
Joined: Mon Mar 08, 2021 10:55 pm
Projects: Arkan'sTower, Gemshine Lorelei!
Location: France
Contact:

Re: Character Stats Question

#2 Post by laure44 » Sun Aug 14, 2022 6:27 pm

It can be quite simple to do.

You'd need a few variables and a screen.

Code: Select all

default stat_kindness = 0
default stat_strength = 0
default stat_magic = 0
default available_points = 5

screen Stats():
    vbox align(.5,.5):
        # You can repeat the below for each stat
        hbox:
            text "Kindness"
            null width 30
            textbutton "-":
                action SetVariable("stat_kindness", stat_kindness-1), SetVariable("available_points", available_points+1)
                if stat_kindness <= 0:
                    sensitive False # Only if you don't want the stat to be below 0
            text str(stat_kindness)
            textbutton "+":
                action SetVariable("stat_kindness", stat_kindness+1), SetVariable("available_points", available_points-1)
                if available_points <= 0:
                    sensitive False
        text "Available points: [available_points]"
That's just a basic code, I'd also recommend checking the documentation to customize the appearance of your screens.

User avatar
Pink_Juicy
Newbie
Posts: 21
Joined: Tue Feb 09, 2021 4:09 pm
Contact:

Re: Character Stats Question

#3 Post by Pink_Juicy » Sun Aug 14, 2022 6:58 pm

laure44 wrote:
Sun Aug 14, 2022 6:27 pm
It can be quite simple to do.

You'd need a few variables and a screen.

Code: Select all

default stat_kindness = 0
default stat_strength = 0
default stat_magic = 0
default available_points = 5

screen Stats():
    vbox align(.5,.5):
        # You can repeat the below for each stat
        hbox:
            text "Kindness"
            null width 30
            textbutton "-":
                action SetVariable("stat_kindness", stat_kindness-1), SetVariable("available_points", available_points+1)
                if stat_kindness <= 0:
                    sensitive False # Only if you don't want the stat to be below 0
            text str(stat_kindness)
            textbutton "+":
                action SetVariable("stat_kindness", stat_kindness+1), SetVariable("available_points", available_points-1)
                if available_points <= 0:
                    sensitive False
        text "Available points: [available_points]"
That's just a basic code, I'd also recommend checking the documentation to customize the appearance of your screens.
nice!!! thank you!! also, how do you set max points for certain stats?

User avatar
laure44
Regular
Posts: 63
Joined: Mon Mar 08, 2021 10:55 pm
Projects: Arkan'sTower, Gemshine Lorelei!
Location: France
Contact:

Re: Character Stats Question

#4 Post by laure44 » Sun Aug 14, 2022 7:14 pm

Pink_Juicy wrote:
Sun Aug 14, 2022 6:58 pm
nice!!! thank you!! also, how do you set max points for certain stats?
Pretty much the same way you set the minimum amount of points, like so:

Code: Select all

textbutton "+":
    action SetVariable("stat_kindness", stat_kindness+1), SetVariable("available_points", available_points-1)
    if available_points <= 0 or stat_kindness == 10: # change 10 to whatever you want, you could also use a variable to set the maximum if you wanted to
        sensitive False

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]