[英]Getting indentation errors on Python code can't resolve indents
我收到此代碼錯誤。 使用戰斗命令時,我試圖添加一個增強效果。 它似乎只是被縮進錯誤弄亂了。 我正在重制《星球大戰:星系 》游戲。
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
^
是我得到的錯誤。
除了別的,這里的代碼:
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
另外,您可能希望降低return
或將其完全刪除,因為當前它不起作用。
但是我不確定這是否是問題,盡管這肯定是一個問題(除非您給出的整個代碼本身都在另一個函數定義中,在這種情況下,這似乎很奇怪)。
失敗的話,我懷疑您在此處發布代碼時錯誤地縮進了代碼,或者制表符和空格混合在一起(不要這樣做)。
為了確保您沒有混淆空格和制表符,可以使用tabnanny 。 要使用它,只需將終端帶入保存文件的目錄並執行:
>>> python -m tabnanny .
此示例摘自“每周Python模塊”: http : //pymotw.com/2/tabnanny/
根據給出的代碼, 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.