# Binary Deployment - Why Isn't This Working?

#1

Hi all. I’ve been stuck on Binary Deployment for a while, and I can’t figure out where my bug is. My hero (Ritic) will go to the first paladin, but instead of summoning nicely in a line (like I think the code should do), he just sort of summons a haphazard pile there, and then stops summoning altogether. I think I need to paste the whole code, just because I’m really clueless where the problem is. (I know that the `while` loop is infinite right now, but I don’t think that’s the problem.):

``````def decToBase(n, newBase):
if n == 0:
return '0'
else:
e = n//newBase
q = n%newBase
if e == 0:
return str(q)
else:
return decToBase(e, newBase) + str(q)

def getThere(p):
while hero.distanceTo(p) > 2:
else:
hero.move(p)

def fixNumber(s):
if len(s) < 8:
e = 8 - len(s)
for i in range(e):
global s
s = '0' + s
return s

def summoner(s):
s = fixNumber(s)
for i in range(0,7):
n = s[i]
if n == '0':
getThere({'x': hero.pos.x + (3 * i), 'y': hero.pos.y})
hero.summon("soldier")
elif n == '1':
getThere({'x': hero.pos.x + (3 * i), 'y': hero.pos.y})
hero.summon("archer")
elif n == '2':
getThere({'x': hero.pos.x + (3 * i), 'y': hero.pos.y})
hero.summon("griffin-rider")

while True:
getThere({'x': pal.pos.x + 5, 'y': pal.pos.y})
n = pal.deployment
toSummon = decToBase(n, 2)
summoner(toSummon)
warlocks = hero.findByType("warlock")
for war in warlocks:
getThere({'x': war.pos.x + 5, 'y': war.pos.y})
n = war.deployment
toSummon = decToBase(n, 3)
summoner(toSummon)

``````
1 Like
#2

Try using `for` instead of `while True`

2 Likes
#3

@Chaboi_3000 Yeah, you’re right, I didn’t need a `while` there at all, come to think of it. I took it out, but now there’s still an infinite loop. I think it has to be coming from the `getThere` function I made. I’m going to take it out and see if that cures it.

#4

Strange… now I’m getting errors in the `summoner` function: `TypeError: Cannot read property 'length' of undefined` - actually that particular error was when I changed the `for` loop in `summoner` to `for i in range(len(s)):`

I think it has to mean that `len` can’t read how many characters one string has. Fine. But it also wasn’t working when I just used `for i in range(7):` or `for i in range(0,7):` Does anyone know what’s wrong with my loop?

1 Like