0

我收到此代码错误。当我使用战斗命令时,我正在尝试添加一个增益。它似乎只是被缩进错误弄乱了。我正在重新制作游戏星球大战星系

代码

import sys

def setup(core, actor, target, command):
    command.setBuffNameTarget('of_deb_def_1')
if actor.getSkill('expertise_of_advanced_paint_1'):
    command.setBuffNameTarget('of_adv_paint_debuff_1')
if actor.getSkill('expertise_of_paint_expose_1'):
    command.setBuffNameTarget('of_adv_paint_expose_1')
    return

def preRun(core, actor, target, command):
    return

def run(core, actor, target, commandString):
    return

错误

File "scripts/commands/combat/of_deb_def_1.py", line 5
if actor.getSkill('expertise_of_advanced_paint_1'):
^
IndentationError: unindent does not match any outer indentation level

^是我得到的错误。

4

3 回答 3

4

除此之外,这里的代码:

if actor.getSkill('expertise_of_advanced_paint_1'):
    command.setBuffNameTarget('of_adv_paint_debuff_1')
if actor.getSkill('expertise_of_paint_expose_1'):
    command.setBuffNameTarget('of_adv_paint_expose_1')
    return

需要缩进。更正的代码:

def setup(core, actor, target, command):
    command.setBuffNameTarget('of_deb_def_1')
    if actor.getSkill('expertise_of_advanced_paint_1'):
        command.setBuffNameTarget('of_adv_paint_debuff_1')
    if actor.getSkill('expertise_of_paint_expose_1'):
        command.setBuffNameTarget('of_adv_paint_expose_1')
        return

此外,您可能想要 dedentreturn或完全删除它,因为目前它没有效果。

但是我不确定这是否是问题所在,尽管这肯定是一个问题(除非您给出的整个代码本身在另一个函数定义中,在这种情况下这看起来很奇怪)。

如果做不到这一点,我怀疑您在此处发布代码时错误地缩进了代码,或者混合了制表符和空格(不要这样做)。

于 2013-10-22T14:36:02.477 回答
1

为了确保您没有混淆空格和制表符,您可以使用tabnanny。要使用它,只需使用终端进入保存文件的目录并执行它:

>>> python -m tabnanny .

此示例取自本周 Python 模块:http: //pymotw.com/2/tabnanny/

于 2013-10-22T14:46:27.010 回答
0

根据给出的代码,看起来从第一行开始的 4 行if actor.getSkill应该属于 function setup()

def setup(core, actor, target, command):
    command.setBuffNameTarget('of_deb_def_1')
    if actor.getSkill('expertise_of_advanced_paint_1'):
        command.setBuffNameTarget('of_adv_paint_debuff_1')
    if actor.getSkill('expertise_of_paint_expose_1'):
        command.setBuffNameTarget('of_adv_paint_expose_1')
    return
于 2013-10-22T14:38:34.010 回答