Affection Points

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
User avatar
Dragonstar89
Regular
Posts: 158
Joined: Mon Aug 12, 2013 11:28 pm
Projects: TBA
Organization: SenpaiJake Games/Paperviper
IRC Nick: dstar89
Deviantart: senpai-jake
Skype: dstar_891
Location: West Virginia, USA
Contact:

Affection Points

#1 Post by Dragonstar89 » Sat Aug 17, 2013 11:43 pm

I know this is a seemingly easy thing to script in our games if you're kinda good, good, or an expert with python and have been working with Renpy for months to years now. But, I figured I'd code up a script that could show some new comers who wanna learn how to program their games how to create a neat affection system, and how it can affect choices later on in the game. Here's the code:

Code: Select all

define m = Character('Me', color="#c8ffc8")
define g1 = Character('Mai', color="#c8ffc8")
define g2 = Character('Yui', color="#c8ffc8")
define g3 = Character('Hina', color="#c8ffc8")


# The game starts here.
label start:

# Affection Begin

$girl_one_aff = 0
$girl_two_aff = 0
$girl_three_aff = 0

m "Let's try raising our affection with the girls..!"

m "WARNING: Some choices we make will make the the other girl(s) dislike us more, so be careful!"

menu:
    "Who should I talk to first?"

    "Mai":
        jump choice_mai

    "Yui":
        jump choice_yui

    "Hina":
        jump choice_hina


label choice_mai:

m "Hey, Mai!"

g1 "Oh, Hello! How are you?"

m "I'm doing fine...hey, listen..um.."

menu:
    "What should I ask her?"

    "Wanna go on a date?":
        $girl_one_aff += 5
        $girl_two_aff = 0
        $girl_three_aff -=5
        jump mai_date

    "What have you been up to?":
        $girl_one_aff -=5
        $girl_two_aff = 0
        $girl_three_aff +=5
        jump next_day

label mai_date:

g1 "A date? *blush* O-of course!"

m "{i}Wow, can't believe it was that easy...{/i}"

"You and Mai go on a date. You both drink warm cider on the boardwalk, and then enjoy the rest of the evening at the beach."

m "{i}Wow, Mai is a real nice girl..{/i}"

"Mai looks into your eyes, smiling."

menu:
    "What do you do?"

    "Make my move!":
        $girl_one_aff += 10
        $girl_two_aff -= 5
        $girl_three_aff -= 20
        "You lean in, and kiss Mai. She is surprised, but for a moment you can see true love in her eyes."
        g1 "..I love you!"
        jump next_day

    "Hug her, and head back home..?":
        $girl_one_aff -= 3
        $girl_two_aff = 0
        $girl_three_aff +=3
        m "Well, see you later."
        g1 "Oh...okay..."
        jump next_day

label choice_yui:

"You run into Yui at a restaurant near your home."

m "Hey, Yui!"

g2 "Hey, you! What's up?"

menu:
    "What shall I answer?"

    "Do you...wanna go on a date?":
        $girl_one_aff -= 5
        $girl_two_aff -= 5
        $girl_three_aff = 0
        g2 "I wouldn't necessarily call it a date, but fine. Whatever."
        jump yui_date

    "Just asking.":
        $girl_one_aff = 0
        $girl_two_aff -= 10
        $girl_three_aff = 0
        jump next_day

label yui_date:

"You and Yui go to a club down the road to have some drinks and dance. It's normal fun as friends..."
"Then, you realize you may be a bit tipsy.."

g2 "Are you sure you're feeling alright, hm?"

menu:
    "What to say?"

    "Say nothing. Just go for a kiss!":
        $girl_one_aff -= 20
        $girl_two_aff += 15
        $girl_three_aff -= 10
        "To your surprise, after you've realised what you've done, Yui kisses back! Congrats!"
        g2 "That was..amazing!"
        jump next_day

    "I'm alright, thanks for caring..":
        $girl_one_aff = 0
        $girl_two_aff -= 10
        $girl_three_aff = 0
        jump next_day

label choice_hina:

m "Hey there, Hina!"

g3 "Hey. What's up??"

menu:
    "What's your answer?"

    "Wanna..erm...go on a date?":
        $girl_one_aff = 0
        $girl_two_aff -= 10
        $girl_three_aff += 10
        g3 "OOOOH! I'd LOOOOOOOOOOOVE TOO! HEHEHE, I'M SO HAPPY YOU ASKED!"
        jump hina_date

    "Just walking around.":
        $girl_one_aff = 0
        $girl_two_aff = 0
        $girl_three_aff -= 20
        g3 "Oh..um...okay.."
        jump next_day

label hina_date:

"You and Hina go to your home, and play video games. You're surpsied with her skills." 

m "Wow, Hina. You're really good at this game."

g3 "Thank you!!!"

"She looks at you for a good moment with a lovely smile and a glare in her eyes."

menu:
    "What will you do?"

    "Go in for a kiss!":
        $girl_one_aff -= 5
        $girl_two_aff -= 20
        $girl_three_aff += 25
        "You lean in for the kiss, but surprisingly, Hina kisses you first!"
        g3 "You don't know how long I've waited for this :) ...."
        jump next_day

    "Continue the game.":
        $girl_one_aff = 0
        $girl_two_aff +=1
        $girl_three_aff -=5
        "You continue the game..."
        "Nothing else interesting happens that night..."
        jump next_day

label next_day:

m "OK! Now that I've talked to the girls, it's time to pop the big question to one of them!"

"It's time to propose to the girl of your interest."

"First, let's see how the girls feel about you!"

"Mai has %(girl_one_aff)d points for you. Yui has %(girl_two_aff)d points for you. And, Hina as %(girl_three_aff)d points for you!"

menu:
    "Who will you marry?"

    "Mai":
        if girl_one_aff <= 9:
            g1 "Marry you? I'm sorry, but I don't like you.."
            jump bad_end
        else:
            $hina_marry = False
            g1 "Ma-marriage! Of course! Oh we're going to have a wonderful wedding!"
            jump good_end

    "Yui":
        if girl_two_aff <= 9:
            g2 "Marriage? AHahah, this is a great joke. If you'r being serious, the answer is no."
            jump bad_end
        else:
            $hina_marry = False
            g2 "I've been waiting for this question! I can't wait to be your wife!"
            jump good_end

    "Hina":
        if girl_three_aff <= 9:
            g3 "Sorry, but you ignored me and broke my heart. I can't marry you..."
            jump bad_end
        else:
            $hina_marry = True
            g3 "YES YES YES YES! I've been waiting for you to ask this my entire life!"
            jump good_end

label bad_end:

"So, you didn't get any of the girls to like you. Nor did you become a husband."

"Too bad. ~Bad ending."

return

label good_end:

"You had a wonderful wedding! Cake, all your friends, your parents, the whole 9 yards."

"Then, you went home for your honeymoon treat.."

if hina_marry:
    "You also found out that Hina has been stalking you since middle school."

else:
    "The end!"

return
At the beginning, each girls feels 0 affection for you, but you wanna marry one of the girls right? So you need to build their affection. This is something a lot of Visual Novels with Love or DSE's will have. Sometimes, you will even see a notification of some sort showing your affection raised/lowered, but this gives newcomers a good feel of what's going on here. NOTE: It's important to keep the blocks as is. Renpy uses Python blocks when coding, and each block will contain a label/name/dialogue,etc and then the data is detailed in the block after the : using four spaces. To test, just copy & paste the code into your script.rpy file.
Effecting Menus and Choices:
Felt like I should add this too, since this topic is old enough for an update, and since my skills with Ren'py have gotten much better over the course of the last few months. Anyways, you can easily make these 'affection' points into so much more, as a way of displaying only certain options in a menu or a certain menu at times, like so:
Hiding/Showing different menus based on Affection Points:

Code: Select all

if girl_one_aff >=5 and girl_one_aff <=10:
    menu:
        "Call Mai.":
            jump call_mai
        "Go on a date with Mai":
            jump date_mai
if girl_two_aff >=5 and girl_two_aff <=10:
    menu:
        "Call Yui.":
            jump call_yui
        "Go on a date with Yui":
            jump date_Yui
The above is a very basic example of how to do this. Basically, if you have more than 5 affection points but less than 10 with Mai or Yui (girl one and girl two), then the menus will show. Naturally, you should define a base menu that won't require any skills and have a menu defined for higher values. Let's get a bit more advanced with it:
Showing certain options based on Affection Points:

Code: Select all

menu:
    "Call Yui.":
        jump call_yui
    "Go on a date with Yui":
        jump date_Yui
    "Activate \'Coffee Mod\' with Yui." if girl_two_aff >=20 and girl_two_aff <=25:
        jump yui_coffee_mod
The above will show a menu with two options by default, and if your affection points with Yui are higher than 20 but less than 25, you can choose the 'Coffee Mod' option (+1 cookie to whoever knows that little reference). You can also add in more to the above that will require the player makes more additional statements in order to see the option:

Code: Select all

menu:
    "Call Yui.":
        jump call_yui
    "Go on a date with Yui":
        jump date_Yui
    "Activate \'Coffee Mod\' with Yui." if yuis_club and girl_two_aff >=20 and girl_two_aff <=25:
        jump yui_coffee_mod
So now, to see the 'Coffee Mod' option, you will need to have the variable yuis_club set on true and the right amount of affection.

Simplified Syntax..of some sort:

Code: Select all

if girl_one_aff >=5 and <=10:
Simplified: If girl one's affection points are greater than 5 but less than 10, do the following.

Code: Select all

if yuis_club and girl_two_aff >=20 and girl_two_aff <=25:
Simplified: If yuis_club is true (Basically, if $yuis_club = True ) and girl two's affection points are greater than 20 and less than 25 do the following:

Those are very basic examples of how to do this, you can get even more in detailed with this but since I've been using something similar in my W.I.P game, I figured I'd share the basics here with you all. You can definitely do much more with this. Hope it helps.
Last edited by Dragonstar89 on Fri Jan 24, 2014 8:15 pm, edited 1 time in total.
Beginning pre-production work on a project in Renpy. After being away for 5 years, it's time to get back in the game 8)

User avatar
trooper6
Lemma-Class Veteran
Posts: 3612
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Affection Points

#2 Post by trooper6 » Sun Aug 18, 2013 2:58 am

Hi!
I didn't get through all of this, but your indentation looks like it is off.

For example, right at the beginning you have this:

Code: Select all

label choice_mai:

m "Hey, Mai!"

g1 "Oh, Hello! How are you?"

m "I'm doing fine...hey, listen..um.."
but it should be:

Code: Select all

label choice_mai:
    m "Hey, Mai!"
    g1 "Oh, Hello! How are you?"
    m "I'm doing fine...hey, listen..um.."
Because of this, I'm not quite sure about the rest of it. It looks like the next menu and the rest of the Mai stuff should all be indented as well. So...indentations!
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Dragonstar89
Regular
Posts: 158
Joined: Mon Aug 12, 2013 11:28 pm
Projects: TBA
Organization: SenpaiJake Games/Paperviper
IRC Nick: dstar89
Deviantart: senpai-jake
Skype: dstar_891
Location: West Virginia, USA
Contact:

Re: Affection Points

#3 Post by Dragonstar89 » Sun Aug 18, 2013 3:08 am

Actually, though you can indent, you don't need to indent for labels, if the label itself is going to be one big thing (like one scene). If you run the code, it all works fine, so I don't think the indent rule really calls for labels.. Haha
Beginning pre-production work on a project in Renpy. After being away for 5 years, it's time to get back in the game 8)

User avatar
trooper6
Lemma-Class Veteran
Posts: 3612
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Affection Points

#4 Post by trooper6 » Sun Aug 18, 2013 1:01 pm

I learn something new every day! Thanks!
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Dragonstar89
Regular
Posts: 158
Joined: Mon Aug 12, 2013 11:28 pm
Projects: TBA
Organization: SenpaiJake Games/Paperviper
IRC Nick: dstar89
Deviantart: senpai-jake
Skype: dstar_891
Location: West Virginia, USA
Contact:

Re: Affection Points

#5 Post by Dragonstar89 » Sun Aug 18, 2013 2:24 pm

No problem :D Also I forgot to include, the only time indentation is called for things under a label is if the label is going to show dialogue because of a true variable. Like:

Code: Select all

if hina_marry:
    "You also found out Hina has been stalking you since middle school."
else:
    "The End!"


Although, that else statement is not needed. I just threw it in for test purposes earlier :lol:
Beginning pre-production work on a project in Renpy. After being away for 5 years, it's time to get back in the game 8)

User avatar
rabcor
Regular
Posts: 81
Joined: Sun Mar 17, 2013 3:07 pm
Projects: None (Need a programmer?)
Organization: Cestarian Games
Contact:

Re: Affection Points

#6 Post by rabcor » Sun Nov 24, 2013 2:07 pm

Dragonstar89 wrote:Actually, though you can indent, you don't need to indent for labels, if the label itself is going to be one big thing (like one scene). If you run the code, it all works fine, so I don't think the indent rule really calls for labels.. Haha
Nice to know, but i think it's good practice to indent it because it's important to keep your code in a easily understandable format. There are reasons why python uses indentation like it does. In short (the part that's applicable here) one is to keep your code in a easily readable format (If you're reading/editing it months or years after first writing it, or better yet if somebody else has to do it). The other reason is that some guy thought it was a good idea to replace

Code: Select all

if{stuff;}
with

Code: Select all

if:
    stuff
since most people would write like this anyways

Code: Select all

if 
{
    stuff;
}
for that readability i just talked about in languages that don't use indentation instead of brackets. /breather

Basically they're using what people were going to put in their code anyways to shorten the code. i mean you can write your code in a straight line (outside of python) but that would be hell to debug.

Even if Ren'Py doesn't seem to require it for it's labels, it is still good practice and i'd highly recommend doing it even if you can get away with not doing it. (At least with any code that really matters to you.)

Thanks for the code btw :D it was helpful.

Off topic: Dir en grey are one of my favorite bands too. :wink:

User avatar
Dragonstar89
Regular
Posts: 158
Joined: Mon Aug 12, 2013 11:28 pm
Projects: TBA
Organization: SenpaiJake Games/Paperviper
IRC Nick: dstar89
Deviantart: senpai-jake
Skype: dstar_891
Location: West Virginia, USA
Contact:

Re: Affection Points

#7 Post by Dragonstar89 » Sun Nov 24, 2013 2:37 pm

rabcor wrote:
Dragonstar89 wrote:Actually, though you can indent, you don't need to indent for labels, if the label itself is going to be one big thing (like one scene). If you run the code, it all works fine, so I don't think the indent rule really calls for labels.. Haha
Nice to know, but i think it's good practice to indent it because it's important to keep your code in a easily understandable format. There are reasons why python uses indentation like it does. In short (the part that's applicable here) one is to keep your code in a easily readable format (If you're reading/editing it months or years after first writing it, or better yet if somebody else has to do it). The other reason is that some guy thought it was a good idea to replace

Code: Select all

if{stuff;}
with

Code: Select all

if:
    stuff
since most people would write like this anyways

Code: Select all

if 
{
    stuff;
}
for that readability i just talked about in languages that don't use indentation instead of brackets. /breather

Basically they're using what people were going to put in their code anyways to shorten the code. i mean you can write your code in a straight line (outside of python) but that would be hell to debug.

Even if Ren'Py doesn't seem to require it for it's labels, it is still good practice and i'd highly recommend doing it even if you can get away with not doing it. (At least with any code that really matters to you.)

Thanks for the code btw :D it was helpful.

Off topic: Dir en grey are one of my favorite bands too. :wink:
I know :) I wrote this in the way I usually style my Python code: crappy and unordered. I may get around to updating it wiht indentation and better organization. With complete Python, indentation is basically a must, but with Ren'py's setup I must've gotten used to the lazy ways of writing dialogue.

Off topic: Yeah, they're an amazing band right?
Beginning pre-production work on a project in Renpy. After being away for 5 years, it's time to get back in the game 8)

User avatar
Kate
Regular
Posts: 196
Joined: Thu Sep 19, 2013 6:10 pm
Projects: Blackout
Organization: Moonlight Otome
Location: United States
Contact:

Re: Affection Points

#8 Post by Kate » Tue Nov 26, 2013 4:09 pm

I have a question about this- when determining which ending the player achieves based upon affection points, does it have to be two options with "if" and "else", or can there be multiple endings with a points range, such as > 5, >5 and <20, and >20? I'm still a novice programmer, hoping to have three endings in my game per character.

Help is appreciated greatly!

User avatar
xavimat
Eileen-Class Veteran
Posts: 1433
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: xavimat
Location: Italy
Contact:

Re: Affection Points

#9 Post by xavimat » Tue Nov 26, 2013 4:17 pm

You have also 'elif'

Code: Select all

if points < 5:
    jump bad_ending
elif points < 20:
    jump normal_ending
else:
    jump best_ending
You can also add several conditions in the same 'if' or 'elif' line with booleans (and, or...)

Code: Select all

if points1 < 5 and points2 < 5:
    jump worst_ending
elif points1 < 20 and points2 < 5:
    jump first_ending
elif points1 < 5 and points2 < 20:
    jump second_ending
else:
    jump best_ending
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Cops&Robbers A two-player experiment
Fear&Love Why can’t we simply express our feelings? Why am I afraid to say ‘I love you’?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
Kate
Regular
Posts: 196
Joined: Thu Sep 19, 2013 6:10 pm
Projects: Blackout
Organization: Moonlight Otome
Location: United States
Contact:

Re: Affection Points

#10 Post by Kate » Mon Dec 02, 2013 2:08 pm

Oh! Many thanks :) That is very helpful!
Current Project:
Blackout [VN][Romance][GxB][Mystery][Suspense] http://lemmasoft.renai.us/forums/viewto ... 43&t=34118
"It is the duty of authors to make the fantastic seem ordinary and the ordinary seem fantastic." - K. Auer

ocimpean
Newbie
Posts: 24
Joined: Tue Aug 27, 2013 9:13 pm
Location: Florida
Contact:

Re: Affection Points

#11 Post by ocimpean » Fri Jan 24, 2014 8:10 am

Thank you so much for posting this example, it helps me understand a little bit more how to do things in Ren'Py!

User avatar
Dragonstar89
Regular
Posts: 158
Joined: Mon Aug 12, 2013 11:28 pm
Projects: TBA
Organization: SenpaiJake Games/Paperviper
IRC Nick: dstar89
Deviantart: senpai-jake
Skype: dstar_891
Location: West Virginia, USA
Contact:

Re: Affection Points

#12 Post by Dragonstar89 » Fri Jan 24, 2014 8:16 pm

ocimpean wrote:Thank you so much for posting this example, it helps me understand a little bit more how to do things in Ren'Py!
Glad to hear it :D Anyways, I added more to the main topic on how points can effect menus/choices, hope everyone finds it helpful.
Beginning pre-production work on a project in Renpy. After being away for 5 years, it's time to get back in the game 8)

salceous
Newbie
Posts: 19
Joined: Sun Apr 09, 2017 12:12 pm
itch: shuttt
Contact:

Re: Affection Points

#13 Post by salceous » Tue Apr 11, 2017 12:24 pm

I know this post is really old, but if I have 7 guys that the player can go after (I know that's a lot of guys but I have my reasons haha), do I still have to list every effect that the choice will have on each of the guys, even if it doesn't affect most of them? Like only one of them will get + affection while the other 6 of them get +/-0 affection.

User avatar
Dragonstar89
Regular
Posts: 158
Joined: Mon Aug 12, 2013 11:28 pm
Projects: TBA
Organization: SenpaiJake Games/Paperviper
IRC Nick: dstar89
Deviantart: senpai-jake
Skype: dstar_891
Location: West Virginia, USA
Contact:

Re: Affection Points

#14 Post by Dragonstar89 » Wed Nov 15, 2017 6:56 pm

salceous wrote:
Tue Apr 11, 2017 12:24 pm
I know this post is really old, but if I have 7 guys that the player can go after (I know that's a lot of guys but I have my reasons haha), do I still have to list every effect that the choice will have on each of the guys, even if it doesn't affect most of them? Like only one of them will get + affection while the other 6 of them get +/-0 affection.
That depends on how you want the decisions to affect the other characters. If you want a choice to simply raise affection, then just leave out the changes to the other character's stores and up the character that will have it change. While I don't have the time atm to write it, I'm certain you can use more harder Python code to create an instance for easily maintaining all the character's points in one go, and connect a function to it to update when you need it to.
Beginning pre-production work on a project in Renpy. After being away for 5 years, it's time to get back in the game 8)

Errilhl
Regular
Posts: 163
Joined: Wed Nov 08, 2017 4:32 pm
Projects: HSS
Contact:

Re: Affection Points

#15 Post by Errilhl » Thu Nov 16, 2017 9:35 pm

You do not need to write in the ones where there is no change to the affection level. You'll be fine just modifying the values that are actually modified. So something like:

Code: Select all

$ char1_aff += 5
$ char3_aff -= 3
# leave char2, char4, char5, char6, char7 off, since their levels don't get affected
Currently working on: Image

Post Reply

Who is online

Users browsing this forum: No registered users