RenPy Beginner - Questions

webmasterjunkie

New Member
Jul 23, 2023
2
0
Hi All,

Working on whether or not I can create a VN. I am just running into things that don't make sense. Hoping this can be a place I ask some pretty basic questions and get some guidance on. Probably the first hiccup I am seeing is around OOP in my code. I am just working on functionality bits to ensure I can build the VN I am thinking about. I am creating an "Actor" class:

Code:
### Actor Object
init python:
    class Actor:
        def __init__(self, character, name, relationship, affection = 0):
            self.character = character
            self.name = name
            self.relationship = relationship

        def affectionUp(self, amount):
            self.affection += amount
            renpy.notify(self.name + " liked that!")

        def affectionDown(self, amount):
            self.affection -= amount
            renpy.notify(self.name + " will remember that!")
I have a pretty basic statement for it that looks like this:

Code:
define mel = Actor(
    Character("Melissa", who_color = "#213fe9"),
    "Melissa",
    "Neighbor"
    )
This all works fine up until here:

Code:
    mel.character "[mc.name], do you like me?"
    menu:
        "Yes":
            $ mel.affectionUp(1)
            mel.character "Thanks!"

        "No":
            $ mel.affectionDown(1)
            mel.character "Ouch"
RenPy tosses me this:

Code:
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/story/intro.rpy", line 28, in script
    $ mel.affectionUp(1)
  File "game/story/intro.rpy", line 28, in <module>
    $ mel.affectionUp(1)
AttributeError: 'Actor' object has no attribute 'affectionUp'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/story/intro.rpy", line 28, in script
    $ mel.affectionUp(1)
  File "C:\Program Files\RenPy\renpy\ast.py", line 823, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Program Files\RenPy\renpy\python.py", line 1178, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/story/intro.rpy", line 28, in <module>
    $ mel.affectionUp(1)
AttributeError: 'Actor' object has no attribute 'affectionUp'

Windows-10-10.0.22631 AMD64
Ren'Py 8.2.3.24061702
Anyone have any insight into what could be causing this? I have checked my indentation but I am using all spaces and indented as needed I think.
 

webmasterjunkie

New Member
Jul 23, 2023
2
0
Disregard. Seems VS Code was creating a running cache of my files and RenPy wasn't getting my latest version. Mod can delete post if they like!
 

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,278
3,916
"define" keyword is for constants that will not change. So when you did "define mel = Actor(...)" it's not going to do what you intend because later when you save games the changes to the object properties won't be persisted, which can lead to some confusing bugs.

tl;dr: Should use "default mel = Actor(...)"