How to add ability points to screen?

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
DewyNebula
Newbie
Posts: 7
Joined: Sun Apr 21, 2024 10:57 am
Contact:

How to add ability points to screen?

#1 Post by DewyNebula »

Hello. I recently got a character creator working with the ability to name and change the character's appearance on one screen. I would also like to add an ability point system, where you would have eight default points in Strength, Dexterity, Constitution, Intelligence, Wisdom, and Charisma. You would have 27 points to spend, with the stats reaching 15. I've looked through various guides on how to do this, but they do not cover how to do it on a screen.

What I would like to achieve is the ability point spend amount (27) to be shown at the top right of the screen, decreasing when spending points. Below would be the list of attributes, with image buttons increasing or decreasing the points. Below is my current code. Feel free to comment on other improvements I should make.

Code: Select all

label player_name:
    init python:
        def name_func(newstring):
            store.myname = newstring
    init:
        default myname = ""

label characters:
    # Characters
    define k = Character("Kelsey")

label character_creation:
    # Asset variables
    default skin = 1
    default mouth = 1
    default nose = 1
    default irises = 1
    default eyes = 1
    default haircolor = 1
    default hair = 1

    # Layered Images
    layeredimage player:
        # Skin color
        if skin == 1:
            "cc-skin-1-pale"                           
        if skin == 2:
            "cc-skin-2-fair"
        if skin == 3:
            "cc-skin-3-medium" 
        if skin == 4:
            "cc-skin-4-olive" 
        if skin == 5:
            "cc-skin-5-brown"  
        if skin == 6:
            "cc-skin-6-dark-brown" 

        # Mouth and color
        if mouth == 1 and skin == 1:
            "cc-mouth-small-1-pale"
        elif mouth == 1 and skin == 2:
            "cc-mouth-small-2-fair"
        elif mouth == 1 and skin == 3:
            "cc-mouth-small-3-medium"
        elif mouth == 1 and skin == 4:
            "cc-mouth-small-4-olive"
        elif mouth == 1 and skin == 5:
            "cc-mouth-small-5-brown"
        elif mouth == 1 and skin == 6:
            "cc-mouth-small-6-dark-brown" 
        if mouth == 2 and skin == 1:
            "cc-mouth-large-1-pale"
        elif mouth == 2 and skin == 2:
            "cc-mouth-large-2-fair"
        elif mouth == 2 and skin == 3:
            "cc-mouth-large-3-medium"
        elif mouth == 2 and skin == 4:
            "cc-mouth-large-4-olive"
        elif mouth == 2 and skin == 5:
            "cc-mouth-large-5-brown"
        elif mouth == 2 and skin == 6:
            "cc-mouth-large-6-dark-brown" 

        # Nose and color
        if nose == 1 and skin == 1:
            "cc-nose-small-1-pale"
        elif nose == 1 and skin == 2:
            "cc-nose-small-2-fair"
        elif nose == 1 and skin == 3:
            "cc-nose-small-3-medium"
        elif nose == 1 and skin == 4:
            "cc-nose-small-4-olive"
        elif nose == 1 and skin == 5:
            "cc-nose-small-5-brown"
        elif nose == 1 and skin == 6:
            "cc-nose-small-6-dark-brown" 
        if nose == 2 and skin == 1:
            "cc-nose-large-1-pale"
        elif nose == 2 and skin == 2:
            "cc-nose-large-2-fair"
        elif nose == 2 and skin == 3:
            "cc-nose-large-3-medium"
        elif nose == 2 and skin == 4:
            "cc-nose-large-4-olive"
        elif nose == 2 and skin == 5:
            "cc-nose-large-5-brown"
        elif nose == 2 and skin == 6:
            "cc-nose-large-6-dark-brown" 

        # Irises color
        if irises == 1:
            "cc-irises-1-blue"                           
        if irises == 2:
            "cc-irises-2-grey"
        if irises == 3:
            "cc-irises-3-green" 
        if irises == 4:
            "cc-irises-4-hazel" 
        if irises == 5:
            "cc-irises-5-amber"  
        if irises == 6:
            "cc-irises-6-ebony"

        # Eyes and color
        if eyes == 1 and haircolor == 1:
            "cc-eyes-small-1-blond"
        elif eyes == 1 and haircolor == 2:
            "cc-eyes-small-2-ginger"
        elif eyes == 1 and haircolor == 3:
            "cc-eyes-small-3-caramel"
        elif eyes == 1 and haircolor == 4:
            "cc-eyes-small-4-cinnamon"
        elif eyes == 1 and haircolor == 5:
            "cc-eyes-small-5-chocolate"
        elif eyes == 1 and haircolor == 6:
            "cc-eyes-small-6-black"
        if eyes == 2 and haircolor == 1:
            "cc-eyes-large-1-blond"
        elif eyes == 2 and haircolor == 2:
            "cc-eyes-large-2-ginger"
        elif eyes == 2 and haircolor == 3:
            "cc-eyes-large-3-caramel"
        elif eyes == 2 and haircolor == 4:
            "cc-eyes-large-4-cinnamon"
        elif eyes == 2 and haircolor == 5:
            "cc-eyes-large-5-chocolate"
        elif eyes == 2 and haircolor == 6:
            "cc-eyes-large-6-black"

        # Hair and color
        if hair == 1 and haircolor == 1:
            "cc-hair-wavy-1-blond"
        elif hair == 1 and haircolor == 2:
            "cc-hair-wavy-2-ginger"
        elif hair == 1 and haircolor == 3:
            "cc-hair-wavy-3-caramel"
        elif hair == 1 and haircolor == 4:
            "cc-hair-wavy-4-cinnamon"
        elif hair == 1 and haircolor == 5:
            "cc-hair-wavy-5-chocolate"
        elif hair == 1 and haircolor == 6:
            "cc-hair-wavy-6-black"                                                                                                               
    
    screen dollmaker(): 
        # Name text
        hbox:
            yalign 0.1
            xalign 0.05

            text "player name:"
        # Name input           
        hbox:
            yalign 0.1
            xalign 0.21
            xsize 1000 
        
            add Input(default=myname, changed=name_func, length=10)
        # Player body
        hbox:
            yalign 0.5
            xalign 0.5
            spacing 100

            add "player"
        # Left arrow buttons
        vbox:
            yalign 0.7
            xalign 0.045
            spacing 10

            imagebutton auto "ui-arrow-%s-left" action Function(change_player, "hair", "-")
            imagebutton auto "ui-arrow-%s-left" action Function(change_player, "haircolor", "-")
            imagebutton auto "ui-arrow-%s-left" action Function(change_player, "eyes", "-")
            imagebutton auto "ui-arrow-%s-left" action Function(change_player, "irises", "-")
            imagebutton auto "ui-arrow-%s-left" action Function(change_player, "nose", "-")
            imagebutton auto "ui-arrow-%s-left" action Function(change_player, "mouth", "-")
            imagebutton auto "ui-arrow-%s-left" action Function(change_player, "skin", "-")
        # Body text
        vbox:
            yalign 0.67
            xalign 0.145
            spacing 130

            text "hair" xalign 0.5
            text "hair color" xalign 0.5
            text "eyes" xalign 0.5
            text "irises" xalign 0.5
            text "nose" xalign 0.5
            text "mouth" xalign 0.5
            text "skin" xalign 0.5
        # Right arrow buttons
        vbox:
            yalign 0.7
            xalign 0.25
            spacing 10     
            
            imagebutton auto "ui-arrow-%s-right" action Function(change_player, "hair", "+")
            imagebutton auto "ui-arrow-%s-right" action Function(change_player, "haircolor", "+")
            imagebutton auto "ui-arrow-%s-right" action Function(change_player, "eyes", "+")
            imagebutton auto "ui-arrow-%s-right" action Function(change_player, "irises", "+")
            imagebutton auto "ui-arrow-%s-right" action Function(change_player, "nose", "+")
            imagebutton auto "ui-arrow-%s-right" action Function(change_player, "mouth", "+")
            imagebutton auto "ui-arrow-%s-right" action Function(change_player, "skin", "+")
        # Finished character
        vbox:
            yalign 0.9
            xalign 0.8

            textbutton "Done" action Return()

    init python:
        def change_player(aspect, way):
            global hair
            global haircolor
            global eyes
            global irises
            global nose
            global mouth
            global skin
            
            if aspect == "hair":
                if way == "+":
                    hair += 1
                if way == "-":
                    hair -= 1
            
            if hair > 1:
                hair = 1
            if hair < 1:
                hair = 1

            if aspect == "haircolor":
                if way == "+":
                    haircolor += 1
                if way == "-":
                    haircolor -= 1
            
            if haircolor > 6:
                haircolor = 1
            if haircolor < 1:
                haircolor = 6
            
            if aspect == "eyes":
                if way == "+":
                    eyes += 1
                if way == "-":
                    eyes -= 1
            
            if eyes > 2:
                eyes = 1
            if eyes < 1:
                eyes = 2
            
            if aspect == "irises":
                if way == "+":
                    irises += 1
                if way == "-":
                    irises -= 1
            
            if irises > 6:
                irises = 1
            if irises < 1:
                irises = 6

            if aspect == "nose":
                if way == "+":
                    nose += 1
                if way == "-":
                    nose -= 1
            
            if nose > 2:
                nose = 1
            if nose < 1:
                nose = 2
            
            if aspect == "mouth":
                if way == "+":
                    mouth += 1
                if way == "-":
                    mouth -= 1
            
            if mouth > 2:
                mouth = 1
            if mouth < 1:
                mouth = 2
        
            if aspect == "skin":
                if way == "+":
                    skin += 1
                if way == "-":
                    skin -= 1
            
            if skin > 6:
                skin = 1
            if skin < 1:
                skin = 6

# Game Start
label start:
    scene bg black
    with fade
    show friend-kelsey-neutral
    with dissolve

    k "welcome to the game!"

    scene bg creation
    with fade

    #Character Creation
    call screen dollmaker with dissolve
    
    k "hello [myname]"

User avatar
Kia
Eileen-Class Veteran
Posts: 1050
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: How to add ability points to screen?

#2 Post by Kia »

You can use the `Function` action to run a python function when your button is clicked, and that function can check your variables, and change them if the conditions are met.
The harder alternative is using `If` in your actions. You have to study screens a bit more and get familiar with the actions.
https://www.renpy.org/doc/html/screen_actions.html

Post Reply

Who is online

Users browsing this forum: Bing [Bot]