Ren'Py [Solved] Update and Call Function

JustNotFatal

Member
Apr 27, 2017
468
314
I'm trying to have dynamic vars based off of choices handled by a class to be displayed eventually in a GUI. The problem is that when I have var displayed in the dialogue the function is not being called to update said var/attribute.

You don't have permission to view the spoiler content. Log in or register now.

You don't have permission to view the spoiler content. Log in or register now.

Note that these two things are in two separate files. The first "AnnaStatus" should be "Stranger" and the second one should read "Friend"

Thank you in advance.
 

Epadder

Programmer
Game Developer
Oct 25, 2016
568
1,064
Good idea, unfortunately you need some help with the execution. ;)

Python:
init python:
    class Girl(renpy.python.RevertableObject):
        def __init__(self,GFName,GLName,Age,RP,PregC,PregS):
            self.GFName = GFName
            self.GLName = GLName
            self.Age = Age
            self.RP = RP
            self.PregC = PregC
            self.PregS = PregS

        @property
        def RelStatus (self):
            if self.RP >= 15:
                return "Girlfriend"
            elif self.RP >= 10:
                return "Friend"
            elif self.RP >= 3:
                return "Acquaintance"
            else:
                return "Stranger"

        def PregRes (PregC,PregS):
            if self.PregS ==True:
                self.Pregs = True
            if random.random() < self.PregC:
                self.PregS = True
            else:
                self.PregS = False
            #def SexO():
        #Girls
        #How to update?
Changed the class to inherit from 'renpy.python.RevertableObject' to make sure your custom class participates in rollback correctly.

No longer in __init__ do we declare Status as an attribute, but instead going to make it a property. Although for the logic... if your not going to do a range comparison like '10 < self.RP >= 3', make sure you check the minimum highest value to change the relationship status.

If you hit a return in a function, the rest of the function does not execute.

I didn't touch the next function...

Now in the separate rpy:

Python:
define Law = Character("Anna")
define Abigail = Character("Abigail")
define CEO = Character("Tom")
# The game starts here.

default AnnaStats = Girl("Anna","Kotov",23,0,4,False)

default AbigailStats = Girl("Abigail","Hope",25,5,4,False)

default ChloeStats = Girl("Chloe","X",21,5,4,False)

default Player = Character("[FName] [LName]")

default FName = "Player"

default LName = "McGee"

label EchelonStart:
    scene BG
    "Welcome to Echelons V0.0.1 Alpha"
    $ FName = renpy.input("What is your first name?")
    $ LName = renpy.input("What is your last name")
    jump LawyerOffice

# Lawyer Intro Scene

label LawyerOffice:
    scene law1
    Law "Hi [FName], I'm sorry that we have to meet under this circumstance [AnnaStats.RelStatus]"
    Player "So am I."
    $ AnnaStats.RP +=10
    Law """
    As you know, your Father was an extremely wealthy man.

    As you're the only living family member, you get everything.

    However, your Dad did leave one stipulation so you don't get everything immediately.
    """
    Player "Elaborate?"
    Law """
    I knew your Dad for almost 30 years, every single deal he made, he had me look over the paperwork [AnnaStats.RelStatus].

    His goal always was to make sure things lasted. Obsessed with it to a fault really.

    """
   
    return
So you know if you declare/update variables in 'init python' or as a 'define' those variables do not save... well they don't reliably save. Things in init python typically reset to that state as soon as you close and relaunch the program...

So your character's stats should use 'default' so that they will be maintained when the player saves/loads.

If you need to make a change to a variable during gameplay you use '$' for a single line or just 'python:' if you want to do multiple at once without starting with '$'.

Now the Player, FName, Lname as defaults I changed because they weren't in the posted code... same with 'Law' wasn't a valid character to speak.

Hopefully this will give you enough information to continue on your own.
 

JustNotFatal

Member
Apr 27, 2017
468
314
Good idea, unfortunately you need some help with the execution. ;)

Python:
init python:
    class Girl(renpy.python.RevertableObject):
        def __init__(self,GFName,GLName,Age,RP,PregC,PregS):
            self.GFName = GFName
            self.GLName = GLName
            self.Age = Age
            self.RP = RP
            self.PregC = PregC
            self.PregS = PregS

        @property
        def RelStatus (self):
            if self.RP >= 15:
                return "Girlfriend"
            elif self.RP >= 10:
                return "Friend"
            elif self.RP >= 3:
                return "Acquaintance"
            else:
                return "Stranger"

        def PregRes (PregC,PregS):
            if self.PregS ==True:
                self.Pregs = True
            if random.random() < self.PregC:
                self.PregS = True
            else:
                self.PregS = False
            #def SexO():
        #Girls
        #How to update?
Changed the class to inherit from 'renpy.python.RevertableObject' to make sure your custom class participates in rollback correctly.

No longer in __init__ do we declare Status as an attribute, but instead going to make it a property. Although for the logic... if your not going to do a range comparison like '10 < self.RP >= 3', make sure you check the minimum highest value to change the relationship status.

If you hit a return in a function, the rest of the function does not execute.

I didn't touch the next function...

Now in the separate rpy:

Python:
define Law = Character("Anna")
define Abigail = Character("Abigail")
define CEO = Character("Tom")
# The game starts here.

default AnnaStats = Girl("Anna","Kotov",23,0,4,False)

default AbigailStats = Girl("Abigail","Hope",25,5,4,False)

default ChloeStats = Girl("Chloe","X",21,5,4,False)

default Player = Character("[FName] [LName]")

default FName = "Player"

default LName = "McGee"

label EchelonStart:
    scene BG
    "Welcome to Echelons V0.0.1 Alpha"
    $ FName = renpy.input("What is your first name?")
    $ LName = renpy.input("What is your last name")
    jump LawyerOffice

# Lawyer Intro Scene

label LawyerOffice:
    scene law1
    Law "Hi [FName], I'm sorry that we have to meet under this circumstance [AnnaStats.RelStatus]"
    Player "So am I."
    $ AnnaStats.RP +=10
    Law """
    As you know, your Father was an extremely wealthy man.

    As you're the only living family member, you get everything.

    However, your Dad did leave one stipulation so you don't get everything immediately.
    """
    Player "Elaborate?"
    Law """
    I knew your Dad for almost 30 years, every single deal he made, he had me look over the paperwork [AnnaStats.RelStatus].

    His goal always was to make sure things lasted. Obsessed with it to a fault really.

    """

    return
So you know if you declare/update variables in 'init python' or as a 'define' those variables do not save... well they don't reliably save. Things in init python typically reset to that state as soon as you close and relaunch the program...

So your character's stats should use 'default' so that they will be maintained when the player saves/loads.

If you need to make a change to a variable during gameplay you use '$' for a single line or just 'python:' if you want to do multiple at once without starting with '$'.

Now the Player, FName, Lname as defaults I changed because they weren't in the posted code... same with 'Law' wasn't a valid character to speak.

Hopefully this will give you enough information to continue on your own.
So ironically I was half right when I first did this. Thank you for the advice and reply.
Law is a Lawyer that I didn't include since he wasn't relevant to the situation.

So the go is to progress that relationship throughout the story. If it hits that return does that mean it won't update in the future?

Also is
init python:
AnnaStats.RP += 10
the same as
$ AnnaStats.RP +=10

I read that correctly?


Edit: So I just ran it. The second check does not change from Stranger to Acquaintance . I had to add a "" to object creation as it wanted another parameter

Edit2: I'm an idiot apparently. Thank you, you saved me from a ton of frustration.
 
Last edited:

JustNotFatal

Member
Apr 27, 2017
468
314
I hate to ask for more help but for whatever reason its saying the Choice var are not defined. I looked at the documentation and this is how RenPy Formats it

You don't have permission to view the spoiler content. Log in or register now.
A Var got capitalized twice somehow and I didn't realize you needed to have a default Var. I fixed it.
 
Last edited: