Search code examples
pythonmcedit

TypeError: 'int' object is not iterable (beginning coder)


I need help with this:

structureRegion = box
blocks = 0
for x in xrange(structureRegion.minx,structureRegion.maxx):
    for y in xrange(structureRegion.miny,structureRegion.maxy):
        for z in xrange(structureRegion.minz,structureRegion.maxz):
            if blockAt(x, y, z, level) != 0 or air:
                blocks = blocks + 1
for block in blocks:
    for x in xrange(structureRegion.minx,structureRegion.maxx):
        for y in xrange(structureRegion.miny,structureRegion.maxy):
            for z in xrange(structureRegion.minz,structureRegion.maxz):
                coords2 = []
                coords2.append((x,y,z))
                part1 = ''.join(coords)
                part2 = ''.join(coords2)

When I do use this, I get the error above in the title.

I just wanted to go through each block until there are no more and repeat the code.

Thanks

(This is for Minecraft and for an MCEdit filter by the way)


Solution

  • [...]
    for block in xrange(blocks):
    [...]
    

    Shorter (and with some other mistakes fixed):

    coords2 = []
    
    for x in xrange(box.minx,box.maxx):
        for y in xrange(box.miny,box.maxy):
            for z in xrange(box.minz,box.maxz):
                if blockAt(x, y, z, level) != 0:
                    coords2.append((x,y,z))
    
    part1 = ''.join(coords)
    part2 = ''.join(coords2)