Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Binary Deployment - Why Isn't This Working?


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'
        e = n//newBase
        q = n%newBase
        if e == 0:
            return str(q)
            return decToBase(e, newBase) + str(q)

def getThere(p):
    while hero.distanceTo(p) > 2:
        if hero.distanceTo(p) < 25 and hero.isReady("blink"):

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})
        elif n == '1':
            getThere({'x': hero.pos.x + (3 * i), 'y': hero.pos.y})
        elif n == '2':
            getThere({'x': hero.pos.x + (3 * i), 'y': hero.pos.y})

while True:
    paladins = hero.findByType("paladin")
    for pal in paladins:
        getThere({'x': pal.pos.x + 5, 'y': pal.pos.y})
        n = pal.deployment
        toSummon = decToBase(n, 2)
    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)

1 Like

Try using for instead of while True


@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.


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