【发布时间】:2014-04-13 19:27:50
【问题描述】:
我从我正在编辑的 MCEDit 过滤器中获得了这段代码:
def getCommand(level, box):
for x in xrange(box.minx,box.maxx):
for y in xrange(box.miny,box.maxy):
for z in xrange(box.minz,box.maxz):
t = level.tileEntityAt(x, y, z)
if t and t["id"].value == "Control":
if "id" in t: del t["id"]
if "x" in t: del t["x"]
if "y" in t: del t["y"]
if "z" in t: del t["z"]
return (t, x, y, z)
return (None, None, None, None)
我得到这个错误:
'KeyError: 'Key x not found.'
请帮忙!
编辑:
已修复,谢谢@Texelelf:
def getCommand(level, box):
for x in xrange(box.minx,box.maxx):
for y in xrange(box.miny,box.maxy):
for z in xrange(box.minz,box.maxz):
t = deepcopy(level.tileEntityAt(x,y,z))
if t and t["id"].value == "Control":
if "id" in t: del t["id"]
if "x" in t: del t["x"]
if "y" in t: del t["y"]
if "z" in t: del t["z"]
return (t, x, y, z)
return (None, None, None, None)
【问题讨论】:
-
错误是哪一行?我假设它位于
if "x" in t: del t["x"]。你能打印出level.tileEntityAt(x, y, z)做了什么吗? -
其实在line: t = level.tileEntityAt(x, y, z),我真不知道MCEdit能不能打印出什么"level.tileEntityAt(x, y, z)"是的,对不起。
-
如果您有解决方案,您应该将其作为答案发布并标记为已接受。可以回答您自己的问题。
-
@Mike W 好的,做到了,谢谢