simplify personality point system

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
lindsay-jb
Regular
Posts: 68
Joined: Tue Aug 25, 2020 1:05 am
Contact:

simplify personality point system

#1 Post by lindsay-jb »

Hey! So I have three personality points that I'm keeping track of which affect automated MC responses. However, the code I made for it is a little unwieldy. The problem comes when I'm specifying the heirarchy in case they have equal points. I want it to be genuine > sarcastic > aggressive; or in other words, if genuine = sarcastic or genuine = aggressive, then genuine is dominant, and if sarcastic = aggressive, sarcastic is dominant. So whenever I have moments where I specify the type of response, I have to type out this whole thing:

Code: Select all

if genuine > sarcastic and genuine > aggressive or genuine > sarcastic and genuine == aggressive or genuine == sarcastic and genuine > aggressive or genuine == sarcastic and genuine == aggressive:
   	rowan "Dialogue"
        jump ch1_s2_menu3_main

elif sarcastic > genuine and sarcastic > aggressive or sarcastic > genuine and sarcastic == aggressive:
   	rowan "Dialogue"
        jump ch1_s2_menu3_main

elif aggressive > genuine and aggressive > sarcastic:
   	rowan "Dialogue"
        jump ch1_s2_menu3_main
As you can see, it's quite... long. I'm just wondering if there's a way I can set up the weight so I don't have to write that super long statement for the genuine personality every time?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2376
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: simplify personality point system

#2 Post by Ocelot »

As usual, if you want complex behavior from your variables, either make them a class, or shove them in class:

Code: Select all

class Traits:
    def __init__(self):
        self.genuine = 0
        self.sarcastic = 0
        self.aggressive = 0

    @property
    def dominant_trait(self):
        trait = sorted([(self.genuine, 3, 'genuine'), (self.sarcastic, 2, 'sarcastic'), (self. aggressive, 1, 'aggressive')])
        return trait[-1][2]

# Definition of personality variable
default personality = Traits()
# You can easily manipulate individual personality points
    $ personality.sarcastic += 3
    $ personality.aggressive += 3
# And checking dominant trait is pretty easy
if personality.dominant_trait == 'sarcastic':
    # . . .
elif personality.dominant_trait = 'aggressive':
    # . . .
< < insert Rick Cook quote here > >

lindsay-jb
Regular
Posts: 68
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Re: simplify personality point system

#3 Post by lindsay-jb »

Thank you! I've adapted my code to do the points this way. And just a quick verification, how do i establish the hierarchy in case there are ties in points? i'm guessing that's done in the default spot?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2376
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: simplify personality point system

#4 Post by Ocelot »

This code creates a list of tuples (trait_value, tiebreaker, trait_name) and sorts it ascending (largest last). Then it takes last (largest) element (trait[-1]) and extracts name from it (trait[-1][2]).

Tuples are compared by comparing its elements in order. If first element (trait value in my code) of one tuple is larger or smaller that the other, the whole tuple is considered larger or smaller. When those elements are equal (tie in points), Python goes to compare second element in tuples. In my code this element is a tiebreaker. 'Geniune' trait has a tiebreaker value of 3 — larger than any other. If 'Geniune' trait value ties with other trait, it will come on top, because its tiebreaker value will compare higher than one he tied with.
< < insert Rick Cook quote here > >

jeffster
Veteran
Posts: 361
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: simplify personality point system

#5 Post by jeffster »

Without classes:

Code: Select all

init python:
    def resp(r_genuine, r_sarcastic, r_aggressive):
        if sarcastic < aggressive > genuine:
            return r_aggressive
        if sarcastic > genuine:
            return r_sarcastic
        return r_genuine
So every time you need to choose the response automatically, you call that function with those 3 responses for this situation, and it returns the proper one:

Code: Select all

rowan resp("I hear you", "Oh yeah, sure", "Screw you")

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], frankm200