Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python跳过我的第二个for循环_Python_Minecraft - Fatal编程技术网

python跳过我的第二个for循环

python跳过我的第二个for循环,python,minecraft,Python,Minecraft,我正在使用API在minecraft中使用python代码。我有两根柱子,瘦的和胖的,大小不一。我试着把它们建在一个正方形的区域,有点随意。我所有的代码都可以正常工作,直到底部。它运行第一个for循环发布“完成20次中的1次”,然后跳过第二个for循环,将“完成20次中的2次”行发布到游戏聊天中。为什么要跳过第二个for循环 from mcpi.minecraft import Minecraft mc = Minecraft.create() import random import time

我正在使用API在minecraft中使用python代码。我有两根柱子,瘦的和胖的,大小不一。我试着把它们建在一个正方形的区域,有点随意。我所有的代码都可以正常工作,直到底部。它运行第一个for循环发布“完成20次中的1次”,然后跳过第二个for循环,将“完成20次中的2次”行发布到游戏聊天中。为什么要跳过第二个for循环

from mcpi.minecraft import Minecraft
mc = Minecraft.create()
import random
import time
定义如何构建瘦柱

def skinny_pillar(height, blockType):
    global biomex
    global biomez
    y = mc.getHeight(biomex, biomez)
    if (height == 3):
        height = 2
    if (height == 5):
        height = 4

    #Check it won't hit into anything
    count = 0
    block1 = mc.getBlock(biomex - 3, y, biomez)
    block2 = mc.getBlock(biomex + 3, y, biomez)
    block3 = mc.getBlock(biomex, y, biomez - 3)
    block4 = mc.getBlock(biomex, y, biomez + 3)
    while (count != 1):
        if (block1 != 0):
            biomex += 1
        elif (block2 != 0):
            biomex -= 1
        elif (block3 != 0):
            biomez += 1
        elif (block4 != 0):
            biomez -= 1
        else:
            count += 1

    #Base of the pillar
    baseHeight = height
    mc.setBlocks(biomex - 1, y, biomez - 1, biomex + 1, y + baseHeight, biomez + 1, blockType)
    mc.setBlocks(biomex - 2, y, biomez, biomex  + 2, y + baseHeight + 1, biomez, blockType)
    mc.setBlocks(biomex, y, biomez - 2, biomex, y + baseHeight + 1, biomez + 2, blockType)

    #2nd layer of the pillar
    secondHeight = height * 3
    mc.setBlocks(biomex - 1, y, biomez, biomex + 1, y + secondHeight + 1, biomez, blockType)
    mc.setBlocks(biomex, y, biomez - 1, biomex, y + secondHeight + 1, biomez + 1, blockType)

    #Point of the pillar
    pointHeight = height * 6
    mc.setBlocks(biomex, y, biomez, biomex, y + pointHeight, biomez, blockType)

    #Randomlly choose if the pillar will have a rock on top and only put it on the taller ones
    rock = random.randint(1, 100)
    if (height >= 4):
        if (rock >= 70):
            #Layer one
            mc.setBlocks(biomex - 1, y + pointHeight, biomez - 1, biomex + 1, y + pointHeight, biomez + 1, blockType)
            mc.setBlocks(biomex, y + pointHeight, biomez - 2, biomex, y + pointHeight, biomez + 2, blockType)
            #Layer two
            mc.setBlocks(biomex - 2, y + pointHeight + 1, biomez - 1, biomex + 2, y + pointHeight + 1, biomez + 1, blockType)
            mc.setBlocks(biomex - 1, y + pointHeight + 1, biomez - 2, biomex + 1, y + pointHeight + 1, biomez + 2, blockType)
            mc.setBlocks(biomex, y + pointHeight + 1, biomez - 3, biomex, y + pointHeight + 1, biomez + 3, blockType)
            #Layer three
            mc.setBlocks(biomex - 2, y + pointHeight + 2, biomez - 2, biomex + 2, y + pointHeight + 2, biomez + 2, blockType)
            mc.setBlocks(biomex - 1, y + pointHeight + 2, biomez - 3, biomex + 1, y + pointHeight + 2, biomez + 3, blockType)
            mc.setBlocks(biomex , y + pointHeight + 2, biomez - 4, biomex, y + pointHeight + 2, biomez + 4, blockType)
            #Layer four
            mc.setBlocks(biomex - 2, y + pointHeight + 3, biomez - 1, biomex + 2, y + pointHeight + 3, biomez + 1, blockType)
            mc.setBlocks(biomex - 1, y + pointHeight + 3, biomez - 2, biomex + 1, y + pointHeight + 3, biomez + 2, blockType)
            mc.setBlocks(biomex, y + pointHeight + 3, biomez - 3, biomex, y + pointHeight + 3, biomez + 3, blockType)
            #Layer five
            mc.setBlocks(biomex - 1, y + pointHeight + 4, biomez - 1, biomex + 1, y + pointHeight + 4, biomez + 1, blockType)
            mc.setBlocks(biomex, y + pointHeight + 4, biomez - 2, biomex, y + pointHeight + 4, biomez + 2, blockType)
定义如何构建fat支柱

def fat_pillar(height, blockType):
    global biomex
    global biomez
    y = mc.getHeight(biomex, biomez)
    if (height == 3):
        height = 2
    if (height == 5):
        height = 4

    #Check it won't hit into anything
    count = 0
    while (count != 1):
        block1 = mc.getBlock(biomex - 5, y, biomez)
        block2 = mc.getBlock(biomex + 5, y, biomez)
        block3 = mc.getBlock(biomex, y, biomez - 5)
        block4 = mc.getBlock(biomex, y, biomez + 5)
        if (block1 != 0):
            biomex += 1
        elif (block2 != 0):
            biomex -= 1
        elif (block3 != 0):
            biomez += 1
        elif (block4 != 0):
            biomez -= 1
        else:
            count += 1

    #Base of the pillar
    baseHeight = height / 2
    mc.setBlocks(biomex - 3, y, biomez - 2, biomex + 3, y + baseHeight - 1, biomez + 2, blockType)
    mc.setBlocks(biomex - 2, y, biomez - 3, biomex + 2, y + baseHeight - 1, biomez + 3, blockType)
    mc.setBlocks(biomex, y, biomez - 4, biomex, y + baseHeight - 1, biomez + 4, blockType)
    mc.setBlocks(biomex - 4, y, biomez, biomex + 4, y + baseHeight - 1, biomez, blockType)

    #2nd layer of the pillar
    secondHeight = height
    mc.setBlocks(biomex - 2, y, biomez - 1, biomex + 2, y + secondHeight, biomez + 1, blockType)
    mc.setBlocks(biomex - 1, y, biomez - 2, biomex + 1, y + secondHeight, biomez + 2, blockType)
    mc.setBlocks(biomex - 3, y, biomez - 1, biomex + 3, y + secondHeight - 1, biomez + 1, blockType)
    mc.setBlocks(biomex - 1, y, biomez - 3, biomex + 1, y + secondHeight - 1, biomez + 3, blockType)

    #3rd layer of the pillar
    thirdHeight = height * 2
    mc.setBlocks(biomex - 1, y, biomez - 1, biomex + 1, y + thirdHeight, biomez + 1, blockType)
    mc.setBlocks(biomex, y, biomez - 1, biomex, y + thirdHeight + 1, biomez + 1, blockType)
    mc.setBlocks(biomex - 1, y, biomez, biomex + 1, y + thirdHeight + 1, biomez, blockType)

    #Point of the pillar
    pointHeight = height * 3
    mc.setBlocks(biomex, y, biomez, biomex, y + pointHeight, biomez, blockType)

    #Randomlly choose if the pillar will have a rock on top and only put it on the taller ones
    rock = random.randint(1, 100)
    if (height >= 4):
        if (rock >= 70):
            #Layer one
            mc.setBlocks(biomex - 1, y + pointHeight, biomez - 1, biomex + 1, y + pointHeight, biomez + 1, blockType)
            mc.setBlocks(biomex, y + pointHeight, biomez - 2, biomex, y + pointHeight, biomez + 2, blockType)
            #Layer two
            mc.setBlocks(biomex - 2, y + pointHeight + 1, biomez - 1, biomex + 2, y + pointHeight + 1, biomez + 1, blockType)
            mc.setBlocks(biomex - 1, y + pointHeight + 1, biomez - 2, biomex + 1, y + pointHeight + 1, biomez + 2, blockType)
            mc.setBlocks(biomex, y + pointHeight + 1, biomez - 3, biomex, y + pointHeight + 1, biomez + 3, blockType)
            #Layer three
            mc.setBlocks(biomex - 2, y + pointHeight + 2, biomez - 2, biomex + 2, y + pointHeight + 2, biomez + 2, blockType)
            mc.setBlocks(biomex - 1, y + pointHeight + 2, biomez - 3, biomex + 1, y + pointHeight + 2, biomez + 3, blockType)
            mc.setBlocks(biomex , y + pointHeight + 2, biomez - 4, biomex, y + pointHeight + 2, biomez + 4, blockType)
            #Layer four
            mc.setBlocks(biomex - 2, y + pointHeight + 3, biomez - 1, biomex + 2, y + pointHeight + 3, biomez + 1, blockType)
            mc.setBlocks(biomex - 1, y + pointHeight + 3, biomez - 2, biomex + 1, y + pointHeight + 3, biomez + 2, blockType)
            mc.setBlocks(biomex, y + pointHeight + 3, biomez - 3, biomex, y + pointHeight + 3, biomez + 3, blockType)
            #Layer five
            mc.setBlocks(biomex - 1, y + pointHeight + 4, biomez - 1, biomex + 1, y + pointHeight + 4, biomez + 1, blockType)
            mc.setBlocks(biomex, y + pointHeight + 4, biomez - 2, biomex, y + pointHeight + 4, biomez + 2, blockType)
获取所有内容围绕的玩家位置

pos = mc.player.getTilePos()
x = pos.x
z = pos.z
我把这个正方形区域(生物群落)分成多个圆柱。这是第一次。其余的代码与此相同,但坐标定位略有不同

#Make the first column of the biome
c = z -50
d = z -40
for i in range(-50, 0, 10):
    a = x + i
    b = x + (i + 10)
    biomex = random.randint(a, b)
    biomez = random.randint(c, d)
    pillar = random.randint(1, 2)
    if (pillar == 1):
        fat_pillar(random.randint(2, 6), 1)
    else:
        skinny_pillar(random.randint(2, 6), 1)
    time.sleep(0.5)
mc.postToChat("1 of 20 complete")
for i in range(50, 0, -10):
    a = x + i
    b = x + (i - 10)
    biomex = random.randint(a, b)
    biomez = random.randint(c, d)
    pillar = random.randint(1, 2)
    if (pillar == 1):
        fat_pillar(random.randint(2, 6), 1)
    else:
        skinny_pillar(random.randint(2, 6), 1)
    time.sleep(0.5)
mc.postToChat("2 of 20 complete")

它构建列的负坐标部分(第一个for循环)并将该行发布到chat。然后它立即发布第二行,跳过第二个for循环(列的正坐标部分)。我做错了什么?

所以我到处添加文本来显示建议的每件事,发现所有代码都可以正常工作,甚至进入第二个循环的开始,直到
biomex=random.randint(a,b)
我在那行之前添加的文本显示“获得a 117,获得b 107”由此我意识到问题在于a和b的顺序。在第二个循环中,b是较低的数字,a是较高的数字,与第一个循环相反。对于这项工作,我所要做的就是交换a和b,以使较低的数字排在第一位,较高的数字排在最后。如果有,我可能会更早地注意到这一点。

尝试插入调试代码。e、 g.
print(“fat_-pillar()activated!”)
print(“skinny_-pillar successfully created!”)
print(biomex)
在每个函数中查看函数是否以正确的值被激活。for循环本身确实运行,因此您需要更深入地查看。您有一个很好的建议,可以添加打印报表。。。那有什么表现吗?