[SOLVED]AttributeError: type object 'LoveInterest' has no attribute 'affection'

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
User avatar
LilyValley98
Newbie
Posts: 10
Joined: Sat Jul 24, 2021 3:15 pm
Contact:

[SOLVED]AttributeError: type object 'LoveInterest' has no attribute 'affection'

#1 Post by LilyValley98 »

I wanted to make a bar appear in the Character Screen of the love interest but not on the Character Screen of the protagonist. I don't know what I did wrong, please help...

Here is the code for reference since I don't really know what the error wanted me to do.

Code: Select all

screen gameUI:
    imagebutton:
        xalign 1.0
        yalign 0.0
        xoffset -10
        yoffset 10
        auto "UI/characterscreen_%s.png"
        action ShowMenu("CharacterScreenUI")

screen CharacterScreenUI():
    tag characterscreenUI
    add "images/bg gradient.png"
    hbox:
        frame:
            text "Characters"
            style_prefix "characterscreen"
            xpadding 20
            ypadding 20
            background "images/bg leftframe.png"
            ysize 600
            xsize 290
            vbox:
                xalign 0.5
                yalign 0.5
                textbutton _(shin.name):
                    action SetVariable("selectedCharacter", shin)
                    xpadding 80
                    xsize 640
                textbutton _(jin.name):
                    action SetVariable("selectedCharacter", jin)
                    xpadding 80
                    xsize 640

            textbutton _("Return"):
                yalign 0.5
                yoffset 275
                xoffset 10
                action Return ()

        frame:
            text "Character Sheet"
            xpadding 20
            ypadding 20
            background "images/bg rightframe.png"
            ysize 600
            xsize 776
            vbox:
                xoffset 20
                yoffset 40
                text "Name: [selectedCharacter.name]"
                text "Age: [selectedCharacter.age]"
                text "Birthday: [selectedCharacter.birthday]"
                text "Affection: [LoveInterest.affection]"
                bar value LoveInterest.affection xsize 300 xoffset 80

style characterscreen_button_text:
    xalign 0.5

label ShinCharacter:
    "ShinCharacter"
label JinCharacter:
    "JinCharacter"

init python:
    class Player:
        def __init__(self, name = "Shin", age = "18", birthday = "March 3rd"):
            self.name = name
            self.age = age
            self.birthday = birthday

init python:
    class LoveInterest:
        def __init__(self, name = "Jin", age = "18", birthday = "April 5th", affection = 20):
            self.name = name
            self.age = age
            self.birthday = birthday
            self.affection = StaticValue(affection, 100)

default shin = Player(name = "Shin", age = "18", birthday = "March 3rd")
default jin = LoveInterest(name = "Jin", age = "18", birthday = "April 5th", affection = 20)

default selectedCharacter = shin

Here is the error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 13, in execute
    hbox:
  File "game/custom_screens.rpy", line 40, in execute
    frame:
  File "game/custom_screens.rpy", line 47, in execute
    vbox:
  File "game/custom_screens.rpy", line 53, in execute
    text "Affection: [LoveInterest.affection]"
AttributeError: type object 'LoveInterest' has no attribute 'affection'

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

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/ast.py", line 922, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2218, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3006, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3417, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/screen.py", line 432, in visit_all
    callback(self)
  File "renpy/display/core.py", line 3417, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/screen.py", line 443, in per_interact
    self.update()
  File "renpy/display/screen.py", line 631, in update
    self.screen.function(**self.scope)
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 13, in execute
    hbox:
  File "game/custom_screens.rpy", line 40, in execute
    frame:
  File "game/custom_screens.rpy", line 47, in execute
    vbox:
  File "game/custom_screens.rpy", line 53, in execute
    text "Affection: [LoveInterest.affection]"
  File "renpy/text/text.py", line 1620, in _scope
    return self.set_text(self.text_parameter, scope, self.substitute, update)
  File "renpy/text/text.py", line 1644, in set_text
    i, did_sub = renpy.substitutions.substitute(i, scope, substitute)
  File "renpy/substitutions.py", line 270, in substitute
    s = formatter.vformat(s, (), kwargs)
  File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/string.py", line 563, in vformat
  File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/string.py", line 585, in _vformat
  File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/string.py", line 652, in get_field
AttributeError: type object 'LoveInterest' has no attribute 'affection'

Windows-7-6.1.7601-SP1
Ren'Py 7.4.1.1270
Summer Love 1.0
Mon Jul 26 00:40:37 2021
I kept trying to change the code but it would either result in invalid Syntax or NameError so I just left it alone in case something bad happens even more.
Last edited by LilyValley98 on Tue Jul 27, 2021 6:49 am, edited 1 time in total.
New to Ren'Py with No Thoughts, Head Empty.

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

Re: AttributeError: type object 'LoveInterest' has no attribute 'affection'

#2 Post by Ocelot »

text "Affection: [LoveInterest.affection]"
Should be

Code: Select all

if isinstance(selectedCharacter, LoveInterest):
    text "Affection: [selectedCharacter.affection]"
< < insert Rick Cook quote here > >

User avatar
LilyValley98
Newbie
Posts: 10
Joined: Sat Jul 24, 2021 3:15 pm
Contact:

Re: AttributeError: type object 'LoveInterest' has no attribute 'affection'

#3 Post by LilyValley98 »

Ocelot wrote: Sun Jul 25, 2021 1:54 pm text "Affection: [LoveInterest.affection]"
Should be

Code: Select all

if isinstance(selectedCharacter, LoveInterest):
    text "Affection: [selectedCharacter.affection]"
Thank you for replying! but it still doesn't work and still has the same AttributeError problem. I don't know if this is a beginner problem and if so thank you for trying to help me :)

I also gave up trying to make it invisible on the protagonist screen but it would make an AttributeError for the player instead so I'm going to stick with making it not visible on the protagonist screen. I tried other things as well such as changing this

Code: Select all

text "Affection: [selectedCharacter.affection]"
to this

Code: Select all

text "Affection: [LoveInterest.affection]"
and it still didn't work then I changed

Code: Select all

if isinstance(selectedCharacter, LoveInterest):
to this

Code: Select all

if isinstance(LoveInterest)
it resulted in an error.

I read and followed other tutorials and Ren'Py Docs and changed my code, there is still an error but now it changed to AttributeError: type object 'Player' has no attribute 'affection'.

Here is the code:

Code: Select all

screen gameUI:
    imagebutton:
        xalign 1.0
        yalign 0.0
        xoffset -10
        yoffset 10
        auto "UI/characterscreen_%s.png"
        action ShowMenu("CharacterScreenUI")

screen CharacterScreenUI():
    tag characterscreenUI
    add "images/bg gradient.png"
    hbox:
        frame:
            text "Characters"
            style_prefix "characterscreen"
            xpadding 20
            ypadding 20
            background "images/bg leftframe.png"
            ysize 600
            xsize 290
            vbox:
                xalign 0.5
                yalign 0.5
                textbutton _(shin.name):
                    action SetVariable("selectedCharacter", shin)
                    xpadding 80
                    xsize 640
                textbutton _(jin.name):
                    action SetVariable("LoveInterest", jin)
                    xpadding 80
                    xsize 640

            textbutton _("Return"):
                yalign 0.5
                yoffset 275
                xoffset 10
                action Return ()

        frame:
            text "Character Sheet"
            xpadding 20
            ypadding 20
            background "images/bg rightframe.png"
            ysize 600
            xsize 776
            vbox:
                xoffset 20
                yoffset 40
                text "Name: [selectedCharacter.name]"
                text "Age: [selectedCharacter.age]"
                text "Birthday: [selectedCharacter.birthday]"
                if isinstance(selectedCharacter, LoveInterest):
                    text "Affection: [selectedCharacter.affection]"
                bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
                bar range 100

style characterscreen_button_text:
    xalign 0.5

label ShinCharacter:
    "ShinCharacter"
label JinCharacter:
    "JinCharacter"

init python:
    class Player:
        def __init__(self, name = "Shin", age = "18", birthday = "March 3rd"):
            self.name = name
            self.age = age
            self.birthday = birthday

init python:
    class LoveInterest:
        def __init__(self, name = "Jin", age = "18", birthday = "April 5th", affection = 20)
            self.name = name
            self.age = age
            self.birthday = birthday
            self.affection = affection

default shin = Player(name = "Shin", age = "18", birthday = "March 3rd")
default jin = LoveInterest(name = "Jin", age = "18", birthday = "April 5th", affection = 20)

default selectedCharacter = shin
And here is the error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 13, in execute
    hbox:
  File "game/custom_screens.rpy", line 40, in execute
    frame:
  File "game/custom_screens.rpy", line 47, in execute
    vbox:
  File "game/custom_screens.rpy", line 55, in execute
    bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
  File "game/custom_screens.rpy", line 55, in keywords
    bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
  File "game/custom_screens.rpy", line 55, in <module>
    bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
AttributeError: 'Player' object has no attribute 'affection'

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

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/ast.py", line 922, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2218, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3006, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3417, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/screen.py", line 432, in visit_all
    callback(self)
  File "renpy/display/core.py", line 3417, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/screen.py", line 443, in per_interact
    self.update()
  File "renpy/display/screen.py", line 631, in update
    self.screen.function(**self.scope)
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 13, in execute
    hbox:
  File "game/custom_screens.rpy", line 40, in execute
    frame:
  File "game/custom_screens.rpy", line 47, in execute
    vbox:
  File "game/custom_screens.rpy", line 55, in execute
    bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
  File "game/custom_screens.rpy", line 55, in keywords
    bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
  File "game/custom_screens.rpy", line 55, in <module>
    bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
AttributeError: 'Player' object has no attribute 'affection'

Windows-7-6.1.7601-SP1
Ren'Py 7.4.1.1270
Summer Love 1.0
Mon Jul 26 21:17:05 2021
It might be because selectedCharacter and affection are 'connected'? and since I don't want affection to show in the default selectedCharacter which is Shin, that might be why it isn't working. If this is the problem is there a way to make it not 'connected'? I also intend for there to be multiple love interests so will my format work with multiple love interests or does it only work with one?
New to Ren'Py with No Thoughts, Head Empty.

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

Re: AttributeError: type object 'LoveInterest' has no attribute 'affection'

#4 Post by Ocelot »

selectedCharacter.affection tries to get value of affection of whatever is in selectedCharacter variable. When selectedCharacter is shin you have a problem: it does not have an affection field. You need to check if selectedCharacter has it before using it.

Notice that your error changed. Was:

Code: Select all

  File "game/custom_screens.rpy", line 53, in execute
    text "Affection: [LoveInterest.affection]"
AttributeError: type object 'LoveInterest' has no attribute 'affection'
Now:

Code: Select all

  File "game/custom_screens.rpy", line 55, in <module>
    bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
AttributeError: 'Player' object has no attribute 'affection'
First error was fixed. Now the similar error arises in othe place. The fix is the same. In fact, you can apply the same fix to both of those at the same time just by moving bar to the same block as text:

Code: Select all

if isinstance(selectedCharacter, LoveInterest):
    text "Affection: [selectedCharacter.affection]"
    bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
< < insert Rick Cook quote here > >

User avatar
LilyValley98
Newbie
Posts: 10
Joined: Sat Jul 24, 2021 3:15 pm
Contact:

Re: AttributeError: type object 'LoveInterest' has no attribute 'affection'

#5 Post by LilyValley98 »

Ocelot wrote: Mon Jul 26, 2021 9:48 am selectedCharacter.affection tries to get value of affection of whatever is in selectedCharacter variable. When selectedCharacter is shin you have a problem: it does not have an affection field. You need to check if selectedCharacter has it before using it.

Notice that your error changed. Was:

Code: Select all

  File "game/custom_screens.rpy", line 53, in execute
    text "Affection: [LoveInterest.affection]"
AttributeError: type object 'LoveInterest' has no attribute 'affection'
Now:

Code: Select all

  File "game/custom_screens.rpy", line 55, in <module>
    bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
AttributeError: 'Player' object has no attribute 'affection'
First error was fixed. Now the similar error arises in othe place. The fix is the same. In fact, you can apply the same fix to both of those at the same time just by moving bar to the same block as text:

Code: Select all

if isinstance(selectedCharacter, LoveInterest):
    text "Affection: [selectedCharacter.affection]"
    bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
This fixed my screen menu! However, the problem is now when I click on the name of the love interest the error is now 'TypeError: isinstance() arg 2 must be a type or tuple of classes and types' and it also still would not show the bar.
I looked for an answer but I only found people questioning this error with actual python coding and not any ren'py related ones.

There were many terms I didn't know and I couldn't understand any of them. I tried to connect it with any ren'py related docs or other questions but I didn't find anything.

Here is the code: I also changed the setVariable of Shin to be Player instead of selectedCharacter.

Code: Select all

screen gameUI:
    imagebutton:
        xalign 1.0
        yalign 0.0
        xoffset -10
        yoffset 10
        auto "UI/characterscreen_%s.png"
        action ShowMenu("CharacterScreenUI")

screen CharacterScreenUI():
    tag characterscreenUI
    add "images/bg gradient.png"
    hbox:
        frame:
            text "Characters"
            style_prefix "characterscreen"
            xpadding 20
            ypadding 20
            background "images/bg leftframe.png"
            ysize 600
            xsize 290
            vbox:
                xalign 0.5
                yalign 0.5
                textbutton _(shin.name):
                    action SetVariable("Player", shin)
                    xpadding 80
                    xsize 640
                textbutton _(jin.name):
                    action SetVariable("LoveInterest", jin)
                    xpadding 80
                    xsize 640

            textbutton _("Return"):
                yalign 0.5
                yoffset 275
                xoffset 10
                action Return ()

        frame:
            text "Character Sheet"
            xpadding 20
            ypadding 20
            background "images/bg rightframe.png"
            ysize 600
            xsize 776
            vbox:
                xoffset 20
                yoffset 40
                text "Name: [selectedCharacter.name]"
                text "Age: [selectedCharacter.age]"
                text "Birthday: [selectedCharacter.birthday]"
                if isinstance(selectedCharacter, LoveInterest):
                    text "Affection: [selectedCharacter.affection]"
                    bar value StaticValue(selectedCharacter.affection, 100) xsize 300 xoffset 80
                    bar range 100


style characterscreen_button_text:
    xalign 0.5

label ShinCharacter:
    "ShinCharacter"
label JinCharacter:
    "JinCharacter"

init python:
    class Player:
        def __init__(self, name = "Shin", age = "18", birthday = "March 3rd", affection = 50):
            self.name = name
            self.age = age
            self.birthday = birthday
            self.affection = affection

init python:
    class LoveInterest:
        def __init__(self, name = "Jin", age = "18", birthday = "April 5th", affection = 50):
            self.name = name
            self.age = age
            self.birthday = birthday
            self.affection = affection

default shin = Player(name = "Shin", age = "18", birthday = "March 3rd", affection = 50)
default jin = LoveInterest(name = "Jin", age = "18", birthday = "April 5th", affection = 50)

default selectedCharacter = shin
Here is the error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 13, in execute
    hbox:
  File "game/custom_screens.rpy", line 40, in execute
    frame:
  File "game/custom_screens.rpy", line 47, in execute
    vbox:
  File "game/custom_screens.rpy", line 53, in execute
    if isinstance(selectedCharacter, LoveInterest):
  File "game/custom_screens.rpy", line 53, in <module>
    if isinstance(selectedCharacter, LoveInterest):
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types

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

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/ast.py", line 922, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2218, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3006, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3417, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 566, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/screen.py", line 432, in visit_all
    callback(self)
  File "renpy/display/core.py", line 3417, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/screen.py", line 443, in per_interact
    self.update()
  File "renpy/display/screen.py", line 631, in update
    self.screen.function(**self.scope)
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 10, in execute
    screen CharacterScreenUI():
  File "game/custom_screens.rpy", line 13, in execute
    hbox:
  File "game/custom_screens.rpy", line 40, in execute
    frame:
  File "game/custom_screens.rpy", line 47, in execute
    vbox:
  File "game/custom_screens.rpy", line 53, in execute
    if isinstance(selectedCharacter, LoveInterest):
  File "game/custom_screens.rpy", line 53, in <module>
    if isinstance(selectedCharacter, LoveInterest):
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types

Windows-7-6.1.7601-SP1
Ren'Py 7.4.1.1270
Summer Love 1.0
Mon Jul 26 23:27:15 2021
As far as I understand , (selectedCharacter, LoveInterest): is a tuple and LoveInterest is a class and maybe the selectedCharacter is a type? I tried adding Player into the tuple and it made a 'TypeError: isinstance expected 2 arguments got 3' error so I tried to replace selectedCharacter to Player and it made a 'TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types' error.

I gave up trying to have the player not have an affection bar so in the mean time I'm leaving it in but ill try to get rid of it someday.
New to Ren'Py with No Thoughts, Head Empty.

qwertyu63
Newbie
Posts: 6
Joined: Mon Apr 19, 2021 8:19 pm
itch: qwertyu63
Contact:

Re: AttributeError: type object 'LoveInterest' has no attribute 'affection'

#6 Post by qwertyu63 »

I don't know if it's the cause of your problem, but I did find one problem that might be it. Where you have defined your classes, you forgot to note that they are objects. Try this:

Code: Select all

init python:
    class Player(object):
        def __init__(self, name = "Shin", age = "18", birthday = "March 3rd", affection = 50):
            self.name = name
            self.age = age
            self.birthday = birthday
            self.affection = affection

    class LoveInterest(object):
        def __init__(self, name = "Jin", age = "18", birthday = "April 5th", affection = 50):
            self.name = name
            self.age = age
            self.birthday = birthday
            self.affection = affection

User avatar
LilyValley98
Newbie
Posts: 10
Joined: Sat Jul 24, 2021 3:15 pm
Contact:

Re: AttributeError: type object 'LoveInterest' has no attribute 'affection'

#7 Post by LilyValley98 »

qwertyu63 wrote: Mon Jul 26, 2021 12:06 pm I don't know if it's the cause of your problem, but I did find one problem that might be it. Where you have defined your classes, you forgot to note that they are objects. Try this:

Code: Select all

init python:
    class Player(object):
        def __init__(self, name = "Shin", age = "18", birthday = "March 3rd", affection = 50):
            self.name = name
            self.age = age
            self.birthday = birthday
            self.affection = affection

    class LoveInterest(object):
        def __init__(self, name = "Jin", age = "18", birthday = "April 5th", affection = 50):
            self.name = name
            self.age = age
            self.birthday = birthday
            self.affection = affection
Thank you! You made my bar work! but I still have the 'TypeError: isinstance() arg 2 must be a type or tuple of classes and types' problem.
Thanks for helping :D
New to Ren'Py with No Thoughts, Head Empty.

qwertyu63
Newbie
Posts: 6
Joined: Mon Apr 19, 2021 8:19 pm
itch: qwertyu63
Contact:

Re: AttributeError: type object 'LoveInterest' has no attribute 'affection'

#8 Post by qwertyu63 »

Okay, I just read through your code, and you've double-assigned LoveInterest.

You assign that as the name of a class, but then you also make it a variable storing one of your characters with "action SetVariable("LoveInterest", jin)". It's failing because you're asking it to check something that no longer is a class. In Python, you can never give two things the same name, even if they are completely different things.

Change both that and the line "action SetVariable("Player", shin)" above it to set "selectedCharacter" (the new name you were already using) and I think that should clear things up.

User avatar
LilyValley98
Newbie
Posts: 10
Joined: Sat Jul 24, 2021 3:15 pm
Contact:

Re: AttributeError: type object 'LoveInterest' has no attribute 'affection'

#9 Post by LilyValley98 »

qwertyu63 wrote: Mon Jul 26, 2021 7:49 pm Okay, I just read through your code, and you've double-assigned LoveInterest.

You assign that as the name of a class, but then you also make it a variable storing one of your characters with "action SetVariable("LoveInterest", jin)". It's failing because you're asking it to check something that no longer is a class. In Python, you can never give two things the same name, even if they are completely different things.

Change both that and the line "action SetVariable("Player", shin)" above it to set "selectedCharacter" (the new name you were already using) and I think that should clear things up.

Thank you very much! I finally got it to work :D It's still a bit weird since it doesn't show the players affection level in the character screen but I didn't want it to appear in the first place. Also, thank you for explaining why it didn't work, I learned something :)
New to Ren'Py with No Thoughts, Head Empty.

Post Reply

Who is online

Users browsing this forum: Kocker