How to Write a Function That Saves Character Position, Emotion, and Direction?

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
HershallCook
Newbie
Posts: 1
Joined: Mon Aug 22, 2022 8:27 pm
Contact:

How to Write a Function That Saves Character Position, Emotion, and Direction?

#1 Post by HershallCook »

Hello! My partner and I are writing a VN in which we show character 'relationship bars' on screen. These bars indicate how your choices have affected the characters. When there is more than one character on the screen (max of four), I need to custom write code each time for moving the characters to a specific location, fading out the character, and finally fading in the bar. I can do all of this.

However, I have to hard code it each time, and I would rather create a function that does this automatically, by moving the characters to the right spots on the screen and then remembering where they were. That way, if I want to change something, I can change it in one place. So, with that said, here's a video of what it looks like in game: https://youtu.be/eyjU9OrLL1A

Note: that does not include the characters returning to their original positions, which I want.

Here's the code:

Code: Select all

label char_bar:

    $ ben_relate = 80

    scene bg apartment day

    #show calendar onlayer calendar

    show ben at center

    b "This is what happens when a choice occurs."

    show ben at left with move
    hide ben with dissolve
    $ renpy.pause(0.1)
    show screen bar_ben_left with dissolve



menu char_bar_choice1:

        "What should I do?"

        "Inflict massive pain onto this poor fool":

            jump char_bar_bensad

        "Love him immensely, like a pet fish you picked up at a carnival and that you know is going to die soon so you have to make every minute count":

            jump char_bar_benhappy


label char_bar_bensad:
    hide screen bar_ben_left with dissolve
    $ renpy.pause(0.1)
    show screen bar_ben_center with dissolve
    n "You spit on Ben's face. Immediately, you are filled with regret, but Ben's unsmiling face tells you that the damage done."
    $ ben_relate -= 20
    b "That makes me feel really bad. It's like you spit on my values."

    hide screen bar_ben_center with dissolve
    $ renpy.pause(0.1)
    show ben with dissolve

    n "Ben warps back into his usual self. You shake off the effects of your power."
    jump scheme_bar_tester

label char_bar_benhappy:
        hide screen bar_ben_left with dissolve
        $ renpy.pause(0.1)
        show screen bar_ben_center with dissolve
        p "I love you like a pet fish. Which is to say, romantically."
        $ ben_relate += 20
        b "You'd think I wouldn't like that, but actually it makes me feel warm and fuzzy!"


        hide screen bar_ben_center with dissolve
        $ renpy.pause(0.1)
        show ben with dissolve

        n "Ben warps back into his usual self. You shake off the effects of your power."


label scheme_bar_tester:

    scene bg apartment day

    show calendar onlayer calendar

    show richie at center

    s "I am Richie. Will you help me or hurt me?"
    hide richie with dissolve

    show screen bar_scheme_1 with dissolve

    menu scheme_bar_tester_choice2:

            "Hmm...this seems like an opportunity to scheme!"

            "Fuck him up":

                jump scheme_evil

            "Don't do that":

                jump scheme_good

label scheme_evil:


    n "You punch that piece of garbage in the head."

    $ scheme += 20
    $ renpy.pause(1.0)

    r "Uh, rude. I feel you had a nefarious intent by punching me..."

    hide screen bar_scheme_1 with dissolve
    $ renpy.pause(0.1)
    show richie with dissolve
    call scheme_end


label scheme_good:

    p "I wanted to punch you in the head, but I showed restraint instead."

    $ scheme -= 20
    $ renpy.pause(1.0)

    r "I guess that makes you a good person?"

    hide screen bar_scheme_1 with dissolve
    $ renpy.pause(0.1)
    show richie with dissolve
    call scheme_end

label scheme_end:
    r "And now...let's move onto something else!"
    call scheme_option2

label scheme_option2:
    scene bg apartment day

    show calendar at left

    show richie at center

    r "Here Richie says a line."

    call schemetest2


    menu char_bar_choice3:

        "How should I react?"

        "Trick Ben into fighting Stool Boy":

            jump char_bar_stoolsad

        "Coach Ben and Stool Boy into a domestic partnership for the ages" :

            jump char_bar_stoolhappy

label char_bar_stoolsad:
    hide screen bar_ben_1 with dissolve
    $ renpy.pause(0.1)
    show screen bar_ben_center with dissolve
    b "In this version, Ben only says one line before his relationship takes the hit."
    $ ben_relate -= 20
    $ renpy.pause(1.0)


    hide screen bar_ben_center with dissolve
    $ renpy.pause(0.1)
    show ben with dissolve

    n "Ben warps back into his usual self. You shake off the effects of your power."

    hide ben with dissolve
    $ renpy.pause(0.1)
    show screen bar_ben_1 with dissolve
    show richie at right with move
    hide richie with dissolve
    $ renpy.pause(0.1)
    show screen bar_richie_right with dissolve


label schemetest2:
    hide richie
    hide screen scheme_option1 with dissolve
    hide screen scheme_option2 with dissolve
    show ben angry at one
    show richie at four
    show hayley at five
    show jane at seven


    r "Your attitude is really getting on my nerves, Ben!"

    b "How dare you call me by my name! Only my friends can do that, you piece of shit!"

    n "Hmm. My astute emotional senses pick up a touch of distress. If it weren't for my powers, I never would have guessed these two were feuding."

    h "I want to be friends with everyone, so I hate when things go like this! I hope no one makes it worse!"

    j "As a horny goat, I wish to see these two copulate."

    p "Seems like I have a lot of power in this debug menu."



    show ben at bar_1
    show richie at bar_2
    show hayley at bar_3
    show jane at bar_4
    with move
    $ renpy.pause(0.1)
    hide ben
    hide richie
    hide jane
    hide hayley
    with dissolve
    show screen bar_ben_1
    show screen bar_richie_2
    show screen bar_hayley_3
    show screen bar_jane_4
    show screen bar_scheme_1
    with dissolve

menu char_bar_choice4:

    "How should I react?"

    "Trick Ben into fighting Stool Boy":

        jump char_bar_only1

    "Coach Ben and Stool Boy into a domestic partnership for the ages" :

        jump char_bar_only1


label char_bar_only1:
    call hide_bar_fade
    show ben angry at one
    show richie at four
    show hayley at five
    show jane at seven
    with dissolve

    p "What's that, Stool Boy? Ben wears diapers?"

    b "I do not wear diapers! That is ridiculous!"

    n "Ben pulls Stool Boy in close and whispers loudly in his ear."

    b "That was {i}private{/i} information!"

    s "Ben, you know I love your diapers! But I didn't tell anyone about them!"

    call hide_char_fade

    show screen bar_ben_center with dissolve

    b "Why do I wear diapers? Why do my irritable bowels torment me so?"

    call ben_minus_small

    n "He howls into the sky before fixing you with a glare. It's clear Ben suspects you had a role in publicizing his private information."

    call hide_bar_fade

    show screen bar_hayley_center with dissolve

    h "All I wanted was for my ex to be happy."

    call hayley_minus_small

    h "This sucks!"

    call hide_bar_fade

    show screen bar_jane_center with dissolve

    j "Once I was a horny goat, and still I am a horny goat."

    call jane_minus_small

    j "If only you had appeased that hunger."

    call hide_bar_fade

    show screen bar_scheme_1 with dissolve

    n "You survey the emotional wreckage with satisfaction. You cannot believe your childish comment worked as well as it did. Yes, you burned some bridges, but not too badly."

    call scheme_plus_med

    n "And besides: a sad Stool Boy is a less effective Stool Boy, that's certain. You mask your grin before anyone sees it."

I have defined spots for bar_1, bar_2, etc. This is a snippet of that.

Code: Select all

default bar_y = 0.33
default bar_left_x = 0.1
default bar_center_x = 0.5
default bar_right_x = 0.9
default bar_1x = 0.02
default bar_2x = 0.20
default bar_3x = 0.82
default bar_4x = 0.98
default bar_relationship_offset = 100
default bar_relationship_range = 100
default bar_relationship_xsize = 200 #This affects how wide all of the relationship bars are.
default bar_relationship_ysize = 600 #This affects how tall all of the relationship bars are.


#bars. This is BEN.

screen bar_ben_left:
    bar:
        bar_vertical True
        bottom_bar "idle_bar_ben.png"
        top_bar "bar_empty.png"
        thumb "bar_thumb_ben.png"
        value ben_relate
        thumb_offset bar_relationship_offset
        range bar_relationship_range
        xysize (bar_relationship_xsize, bar_relationship_ysize)
        xalign bar_left_x
        yalign bar_y

screen bar_ben_center:
    bar:
        bar_vertical True
        bottom_bar "idle_bar_ben.png"
        top_bar "bar_empty.png"
        thumb "bar_thumb_ben.png"
        value ben_relate
        thumb_offset bar_relationship_offset
        range bar_relationship_range
        xysize (bar_relationship_xsize, bar_relationship_ysize)
        xalign bar_center_x
        yalign bar_y

screen bar_ben_right:
    bar:
        bar_vertical True
        bottom_bar "idle_bar_ben.png"
        top_bar "bar_empty.png"
        thumb "bar_thumb_ben.png"
        value ben_relate
        thumb_offset bar_relationship_offset
        range bar_relationship_range
        xysize (bar_relationship_xsize, bar_relationship_ysize)
        xalign bar_right_x
        yalign bar_y


screen bar_ben_1:
    bar:
        bar_vertical True
        bottom_bar "idle_bar_ben.png"
        top_bar "bar_empty.png"
        thumb "bar_thumb_ben.png"
        value ben_relate
        thumb_offset bar_relationship_offset
        range bar_relationship_range
        xysize (bar_relationship_xsize, bar_relationship_ysize)
        xalign bar_1x
        yalign bar_y


In short: is there a simpler way to do this? I would like to make a custom call that remembers character position, direction, and emotion (e.g., if Ben was angry), and then return to that whenever the one on one moments are complete.

User avatar
Syrale
Regular
Posts: 101
Joined: Sun Oct 25, 2015 10:28 am
Completed: Robot Daycare, Deep Sea Valentine, Locke(d)
Projects: Artificial Selection, Artificial Fashionista, rei_carnation
Github: kigyo
itch: kigyo
Discord: kigyodev
Contact:

Re: How to Write a Function That Saves Character Position, Emotion, and Direction?

#2 Post by Syrale »

renpy.get_attributes would allow you to store a character's current expression: https://www.renpy.org/doc/html/displayi ... attributes

Not sure how well it would work, but one idea would be to just make one "relationship_bar" screen that takes a character's name and position as input:

Code: Select all

screen rel_bar(char, position=0.5):
    $ char_expressions = renpy.get_attributes(char)
    bar:
        bar_vertical True
        bottom_bar "idle_bar_" + char + ".png"
        top_bar "bar_empty.png"
        thumb "bar_thumb_" + char + ".png"
        value relate[char] # I would heavily recommend changing the variables to a dictionary so it's easier to access them
        # ...
        xalign position
        # ...
    
renpy.get_placement might also be worth looking into to scrap the position parameter, but I'm not sure if that works for images or just for screens: https://www.renpy.org/doc/html/displayi ... _placement

It's just a vague idea, but you could then write a function that takes a character name as a parameter, stores their current expression in a variable, hides them, and shows the screen. That way, the variable can later be accessed when showing the character again.
ImageArtificial Selection (ongoing) |ImageDeep Sea Valentine | ImageRobot Daycare (NaNo19)
| ImageArtificial Fashionista (NaNo24)

My Developer Tools: Ren'Py Minimap/Location System | Ren'Py Word Counter+

Post Reply

Who is online

Users browsing this forum: No registered users