简体   繁体   English

在Python代码上出现缩进错误无法解析缩进

[英]Getting indentation errors on Python code can't resolve indents

I am getting an error with this code. 我收到此代码错误。 I'm trying to add a buff when I use a combat command. 使用战斗命令时,我试图添加一个增强效果。 It just seems to be messed up with indentation errors. 它似乎只是被缩进错误弄乱了。 I'm remaking the game Star Wars Galaxies . 我正在重制《星球大战:星系 》游戏。

Code

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

Error 错误

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

^ is the error I get. ^是我得到的错误。

Apart from anything else, the code here: 除了别的,这里的代码:

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

needs to be indented. 需要缩进。 Corrected code: 更正的代码:

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

Also, you may want to dedent return , or remove it entirely as currently it has no effect. 另外,您可能希望降低return或将其完全删除,因为当前它不起作用。

But I'm unsure if this is the problem, although it is certainly a problem (unless the whole code you have given is itself inside another function definition, which would seem odd in this situation). 但是我不确定这是否是问题,尽管这肯定是一个问题(除非您给出的整个代码本身都在另一个函数定义中,在这种情况下,这似乎很奇怪)。

Failing that, I suspect you have either indented your code wrongly when posting it here, or mixed tabs and spaces (don't do that). 失败的话,我怀疑您在此处发布代码时错误地缩进了代码,或者制表符和空格混合在一起(不要这样做)。

In order to assure that you did not mix up spaces and tabs, you can use tabnanny . 为了确保您没有混淆空格和制表符,可以使用tabnanny For using it, simply go with your terminal into the directory where your file is saved and execute it: 要使用它,只需将终端带入保存文件的目录并执行:

>>> python -m tabnanny .

This example is taken from Python Module of the Week: http://pymotw.com/2/tabnanny/ 此示例摘自“每周Python模块”: http : //pymotw.com/2/tabnanny/

According to the code given, it looks like the 4 lines starting from the first if actor.getSkill should fall under the function setup() . 根据给出的代码, if actor.getSkill应该属于函数setup() ,则看起来好像从第一行开始的4行。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM