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

158 views Asked by At

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)

2

There are 2 answers

0
jgierer12 On BEST ANSWER
[...]
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)
0
jwodder On

blocks is an integer, but the line for block in blocks: tries to treat it as though it's iterable (a list, set, tuple, etc.), which it's not, hence the error.