我一直在为Minecraft的Raspberry Pi版本制作一个模组,每当我在程序中输入其中一个命令时,我都会感到非常沮丧的错误。这里是我的代码:来自变量内容的Python NameError
import minecraft.minecraft as minecraft
import minecraft.block as block
import time
mc = minecraft.Minecraft.create();
print('newBlock - Change ID of block to spawn')
print('blockType - Change subID of block to spawn')
print('pos1')
print('pos2')
print('fill - fill specified area')
print('clear - clear specified area')
print
while True:
comm=str(input('Command: '))
if comm=="newBlock":
blockId = int(input('Enter Block ID: '))
mc.postToChat('Block set to ID: ' + str(blockId))
if comm=="blockType":
blockData = int(input('Enter Block Type: '))
if comm=="pos1":
position1 = mc.player.getPos()
mc.postToChat('Set Position 1 as: x' + str(position1.x) + ' y' + str(position1.y) + ' z' + str(position1.z))
if comm=="pos2":
position2 = mc.player.getPos()
mc.postToChat('Set Position 2 as: x' + str(position2.x) + ' y' + str(position2.y) + ' z' + str(position2.z))
if comm=="fill":
mc.setBlocks(position1.x, position1.y, position1.z, position2.x, position2.y, position2.z, blockId, blockType)
mc.postToChat('Filled specified area with: ' + str(blockId))
if comm=="clear":
mc.setBlocks(position1.x, position1.y, position1.z, position2.x, position2.y, position2.z, 0)
mc.postToChat('Cleared specified area')
每次输入是通过变量“通讯”计划吐出此错误消息的用户输入:
Traceback (most recent call last):
File "WorldEditPi.py", line 15, in <module>
comm=str(input('Command: '))
File "<string>", line 1, in <module>
NameError: name 'newBlock(or what ever the user entered into 'comm')' is not defined
请告诉我真的困惑的是,它甚至没有谈论一个变量'newBlock'不是一个变量,它是变量'comm'的内容。这发生在所有命令中,而不仅仅是'newBlock'。