0

我一直在尝试使用 python 编码在 renpy 上制作类似 pesudo RPG 的游戏。我主要将其用作基本测试场,并将我的代码组织到不同的 rpy 文件中。但是现在,我很难将这些技能从子类绑定到主类。这是字符类

#侦探属性

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

默认侦探 = Detective("无名", 5, 5, 5, 5)

我觉得我应该只发布完整的脚本,这样人们就会知道我在寻找什么。尝试应用类似 psudo RPG 的效果,其中侦探类的属性也将带入应该被定义为类的孩子的技能。

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]

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

4

1 回答 1

0

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

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

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

有不止一种方法可以解决这个问题,但我建议让情报成为更复杂的类型,这样你就可以detective.intelligence.raw += 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
于 2021-06-25T03:35:24.677 回答