在 renpy 中获取属性错误,其中 object 没有属性编辑:附加信息

getting attribute error in renpy where object has no attribute EDIT: Additional information

我一直在尝试使用 python 编码在 renpy 上制作类似 RPG 的伪游戏。我主要将其用作基本测试场并将我的代码组织到不同的 rpy 文件中。但是现在,我无法尝试将这些技能从 subclass 与 main class 联系起来。这是字符 class

#侦探属性

class Detective:
    def __init__(self, name, intelligence, psyche, strength, dexterity):
        self.name = name
        self.intelligence = intelligence
        self.psyche = psyche
        self.strength = strength
        self.dexterity = dexterity

#智力技能

class IntSkill(Detective):
    def __init__(self, logic, history, persuasion, deception):
        super().__init__(self, name, intelligence, psyche, strength, dexterity)

        self.logic = logic
        self.history = history
        self.persuasion = persuasion
        self.deception = deception

default detective = Detective("无名", 5, 5, 5, 5)

我觉得我应该 post 完整的剧本,这样人们就会知道我在找什么。尝试应用类似 RPG 的效果,其中侦探 class 的属性也会带入本应定义为 class 的 child 的技能。

label start:


unknown "Can you feel it?"

"..."

unknown "Can you see it?"

"..."

unknown "The spark of life flowing back in your mortal coil."

unknown "It may feel empty, cold and dark at first. That's always the case like this."

unknown "Now, your last moments, do you remember them, child of man?"

unknown "'Sorry detective, but the game was rigged from the start.'"

"First silence,"

"then there was gunfire."

"Three shots were fired."

"The last two were in rapid succession, as though fired at the same time."

unknown "Yes, yes it is exactly as you remember it."

unknown "But do you remember anything after? Anything before?"

"No... I don't think I do."

unknown "Nobody really remembers their experiences after death."

unknown "But most would remember their time before their death. Do you not know?"

" I don't know if I know myself. Who am I?"

unknown "Ahh, scrambled and fried like eggs over an open flame."

"Something happened?"

unknown "Yeah child of man... you died."

"I knew that from what you were saying."

unknown "And do you remember nothing before then?"

"Some double fucking mother fucker with poor fashion sense."

"And a... bird folk?"

unknown "Ah so some memories have survived."

"Why is this happening?"

unknown "Because sometimes the universe has a cosmological joke to play on all of us,"

unknown "even me."

"So what happens now?"

unknown "First I will ask you a couple questions."

menu:
     unknown "What is your most definitive attributes?"

     "My vast intellect to unraveling the Material world":
         $ nameless.intelligence += 2

         jump after_attribute_1

     "My intimate relationship with the Immaterial.":
         $ nameless.psyche += 2

         jump after_attribute_1

     "My martial prowess":
         $ nameless.strength += 2

         jump after_attribute_1

     "My flexability and nimbleness.":
         $ nameless.dexterity += 2

         jump after_attribute_1

label after_attribute_1:

menu:
     unknown "Good... now, what is your weakest trait?"

     "I struggle to grasp the basics of Material science" if nameless.intelligence == 5:
         $ nameless.intelligence -= 2
         jump after_attribute_2

     "I am deaf to the Immaterial." if nameless.psyche == 5:
         $ nameless.psyche -= 2
         jump after_attribute_2

     "I am physically weak." if nameless.strength == 5:
         $ nameless.strength -= 2
         jump after_attribute_2

     "I trip over my own feet."if nameless.dexterity == 5:
         $ nameless.dexterity -= 2
         jump after_attribute_2

label after_attribute_2:

unknown "Now let us see how you handle critical thinking."

unknown "What do you think happened?"

if nameless.intelligence.logic >= 7:
    "\[Passive Logic Successful] I think I got shot in the head."

if nameless.intelligence.logic < 7:
    "Balls if I know"


return

这就是我不断得到的。

[code]
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 126, in script
    if int.logic >= 7:
  File "game/script.rpy", line 126, in <module>
    if int.logic >= 7:
AttributeError: type object 'int' has no attribute 'logic'

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

Full traceback:
  File "game/script.rpy", line 126, in script
    if int.logic >= 7:
  File "renpy/ast.py", line 1892, in execute
    if renpy.python.py_eval(condition):
  File "renpy/python.py", line 2249, in py_eval
    return py_eval_bytecode(code, globals, locals)
  File "renpy/python.py", line 2242, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/script.rpy", line 126, in <module>
    if int.logic >= 7:
AttributeError: type object 'int' has no attribute 'logic'

Windows-10-10.0.19041
Ren'Py 7.4.6.1693
Tales of Tellus Mindthrob 0.1
Thu Jun 24 22:48:31 2021
[/code]

我一直在尝试使用 class 继承者之类的东西,但我不知道我做错了什么。

发生的事情是,当您定义 Detective 时,您传递了一个整数(int 类型)作为情报的值:

                   #  intelligence = 5 ---.
default detective = Detective("nameless", 5, 5, 5, 5)

所以RenPy认为智力是一个整数,而不是具有来自IntSkills的子属性的对象。后来,当你写像 nameless.intelligence.logic >= 7 这样的代码时,它就变得混乱了。 RenPy 认为,“但是智力是一个数字。像数字 4 这样的东西怎么会有逻辑 属性?”

解决这个问题的方法不止一种,但我建议将智力设为更复杂的类型,这样您就可以在需要原始智力得分值(您想要的detective.intelligence 现在正在使用)和 detective.intelligence.logic 用于逻辑分数。

为此,代码可能如下所示:

init python:

    class Detective:
        def __init__(self, name, intelligence, psyche, strength, dexterity):
            self.name = name
            self.intelligence = intelligence
            self.psyche = psyche
            self.strength = strength
            self.dexterity = dexterity
    
    class IntSkills:
        def __init__(self, raw, logic, history, persuasion, deception):
            self.raw = raw
            self.logic = logic
            self.history = history
            self.persuasion = persuasion
            self.deception = deception

default  nameless =     Detective(
        "nameless", 
        IntSkills(10, 2, 2, 4, 5),
        5, 5, 5
 )
define unknown = "Unknown character"

label start:
    # some scene
    scene bg room
    
    # adjust raw intelligence
    $ nameless.intelligence.raw  -= 2

    unknown "Now let us see how you handle critical thinking."    
    unknown "What do you think happened?"
    
    # use logic
    if nameless.intelligence.logic >= 7:
        "\[Passive Logic Successful] I think I got shot in the head."
    
    if nameless.intelligence.logic < 7:
        "Balls if I know"
        
    "You have [nameless.intelligence.raw] base intelligence"
    "You have  [nameless.intelligence.logic] logic"
        
    return