我一直在尝试使用python编码在renpy上制作一个类似于pesudo RPG的游戏。我主要使用它作为基本的测试平台,并将我的代码组织到不同的rpy文件中。但是现在,我在尝试将这些技能从子类绑定到主类时遇到了麻烦。这是character类
#侦探属性
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默认侦探=侦探(“无名”,5,5,5,5)
我觉得我应该把完整的脚本贴出来,这样人们就会知道我在找什么。尝试应用类似于pesudo 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]我一直在尝试使用类继承器之类的东西,但我就是不知道我做错了什么。
发布于 2021-06-25 11:35:25
当您定义侦探时,您传递的是一个整数(类型为int)作为智能的值:
# intelligence = 5 ---.
default detective = Detective("nameless", 5, 5, 5, 5)因此,RenPy认为智能是一个整数,而不是具有IntSkills的子属性的对象。后来,当您编写像nameless.intelligence.logic >= 7这样的代码时,它会变得很混乱。RenPy认为,“但是智能是一个数字,像数字4这样的东西怎么会有逻辑属性呢?”
有不止一种方法可以解决这个问题,但我建议您将智能类型设置为更复杂的类型,这样当您需要原始智能分值(现在用于detective.intelligence )时,就可以执行类似detective.intelligence.raw += 4的操作,而对于逻辑分数,则可以使用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"
returnhttps://stackoverflow.com/questions/68124851
复制相似问题