Summit's Gate - tab unstable/crashing

The sad thing is I’ve only coded the first part, but anytime I change a parameter and hit “run” the tab tends to crash almost immediately. I’ll be the first to admit this is not the most parsimonious code the world has ever seen, but I’m beginning to get really frustrated. Is there anything I could do to make the code less likely to crash? (Also, while I’m asking, I guess I really should ask if there is a way to calculate where a catapult missle is likely to splash down. I can find the missle position (x,y,z) and velocity [ missle[0].velocity.x etc.]. )

Thanks in advance!

def palHeal(pal, troopArray, healthF, selfHealB):
    if pal.canCast("heal"):
        if (selfHealB and (self.health < self.maxHealth*healthF)):
            if self.distanceTo(pal) < 30:
                self.command(pal, "cast", "heal", self)
            else:
                self.command(pal, "move", self.pos)
        else:
            tarA = None
            for tr in troops:
                if ((tr.health/tr.maxHealth < healthF) and (tr.health > 5) and (pal.distanceTo(tr) < 30)):
                    tarA = tr
                    healthF = tr.health / tr.maxHealth
            if tarA:
                self.command(pal, "cast", "heal", tarA)
            else:
                if self.distanceTo(pal) > 30:
                    self.command(pal, "move", self.pos)
                    

def archerTarget(arch, range):
    enemies = arch.findEnemies()
    if len(enemies) < 1:
        answer = None 
    elif len(enemies) < 2:
        answer = enemies[0]
    else:
        answer = arch.findNearest(enemies)
        dToEnemies = arch.distanceTo(answer)
        for enemy in enemies:
            if arch.distanceTo(enemy) < range:
                if ((enemy.maxHealth > answer.maxHealth) and (enemy.health > 0)):
                    answer = enemy
                    dToEnemies = arch.distanceTo(answer)
                elif ((enemy.maxHealth >= answer.maxHealth) and (enemy.health > 0) and arch.distanceTo(enemy) < dToEnemies):
                    answer = enemy
                    dToEnemies = arch.distanceTo(enemy)
    return answer
    
def chainLightning():
    enemies = self.findEnemies()
    if len(enemies) > 4:
        tarA = self.findNearest(enemies)
        if self.distanceTo(tarA) < 30 and tarA.health > 95 and self.canCast("chain-lightning", tarA):
            self.cast("chain-lightning", tarA)
        
#Starting main code
while self.now() < 1:
    self.move(Vector(61,42))


UpFirst = True
stepCounter = 0
maxStep = 5
loop:
    chainLightning()
    catapult = self.findByType("catapult", self.findEnemies())
    #Soldiers' orders
    troops = self.findByType("soldier", self.findFriends())
    if len(troops) > 0:    
        for t in troops:
            if len(catapult) > 0:
                if UpFirst:
                    posA = Vector.add(t.pos, Vector(2, 3))
                    UpFirst = False
                else:
                    posA = Vector.add(t.pos, Vector(2,-3))
                    UpFirst = True
                if self.isPathClear(t.pos, posA):
                    if len(catapult) > 0:
                        self.command(t, "move", posA)
                    self.command(t, "defend", posA)
            else:
                if len(self.findEnemies()) > 0:
                    self.command(t, "attack", t.findNearest(self.fineEnemies()))
    #Archers' orders
    troops = self.findByType("archer", self.findFriends())
    if len(troops) > 0:
        for archer in troops:
            tarA = archerTarget(archer, 15)
            if archer.distanceTo(tarA) < 20 and tarA.type != "door":
                if len(catapult) > 0:
                    if UpFirst:
                        posA = Vector.add(archer.pos, Vector(2,4))
                        UpFirst = False
                    else:
                        posA = Vector.add(archer.pos, Vector(2,-4))
                        UpFirst = True
                    self.command(archer, "move", posA)
                self.command(archer, "attack", tarA)
            else:
                if UpFirst and len(catapult)>0:
                    UpFirst = False
                    posA = Vector.add(archer.pos, Vector(1,3))
                    if self.isPathClear(archer.pos, posA) and len(catapult)>0:
                        self.command(archer, "defend", posA)
                elif len(catapult)>0:
                    UpFirst = True
                    posA = Vector.add(archer.pos, Vector(1,-3))
                    if self.isPathClear(archer.pos, posA) and len(catapult)>0:
                        self.command(archer, "defend", posA)
                else:
                    if tarA.type != "door":
                        self.command(archer, "attack", tarA)
    #Paladins' orders
    troops = self.findByType("paladin", self.findFriends())
    if len(troops) > 0:
        for pal in troops:
            if len(catapult) > 0:
                if UpFirst:
                    UpFirst = False
                    self.command(pal, "move", Vector.add(pal.pos, Vector(-1, 3)))
                else:
                    UpFirst = True
                    self.command(pal, "move", Vector.add(pal.pos, Vector(-1, -3)))
            palHeal(pal, self.findFriends(), 0.6, True)
            
    #Attack on killable targets in range
    if len(self.findEnemies()) > 0:
        tarA = self.findNearest(self.findEnemies())
        while ((len(self.findEnemies()) > 0) and (self.distanceTo(tarA) < self.attackRange) and (tarA.health < self.attackDamage * 2)):
            if self.isReady("bash"):
                self.bash(tarA)
            else:
                self.attack(tarA)
            tarA = self.findNearest(self.findEnemies())
            
    #Moving a soldier and character towards catapults    
    catapult = self.findByType("catapult", self.findEnemies())
    if len(catapult)==2:
        if catapult[0]:
            allTroops = self.findByType("soldier", self.findFriends())
            if len(allTroops) > 0:
                troop = catapult[0].findNearest(allTroops)
                self.command(troop, "attack", catapult[0])
        if catapult[1]:
            allTroops = self.findByType("soldier", self.findFriends())
            if len(allTroops) > 0:
                troop = catapult[1].findNearest(allTroops)
                self.command(troop, "attack", catapult[1])
        stepCounter = stepCounter + 1
        tarA = self.findNearest(catapult)
        if tarA:
            if ((self.distanceTo(tarA) < self.attackRange + 4) or (self.pos.x > 80)):
                self.attack(tarA)
            elif UpFirst:
                if catapult[0]:
                    tarA = catapult[0].pos
                else:
                    tarA = None
                if tarA:
                    self.move(tarA)
                if stepCounter == maxStep:
                    UpFirst = False
                    stepCounter = 0
            else:
                if catapult[1]:
                    self.move(catapult[1].pos)
                if stepCounter == maxStep:
                    UpFirst = True
                    stepCounter = 0            
    elif len(catapult)==1:
        if (catapult[0] and (len(self.findByType("soldier", self.findFriends())) > 0)):
            troop = catapult[0].findNearest(self.findByType("soldier", self.findFriends()))
            self.command(troop, "attack", catapult[0])
        stepCounter = stepCounter + 1
        if stepCounter == maxStep:
            stepCounter = 0
            upFirst = not(upFirst)
        if catapult[0]:
            self.attack(catapult[0])
    else:
        enemies = self.findEnemies()
        if len(enemies) > 0:
            if self.findNearest(enemies).type != "door":
                self.attack(self.findNearest(enemies))
    
    enemies = self.findEnemies()
    if ((len(enemies) < 1) or (len(enemies) == 1 and enemies[0].type == "door")):
        break
    
    
allTroops = self.findFriends()
if len(allTroops) > 0:
    for troop in allTroops:
        self.command(troop, "move", Vector(75,34))
self.moveXY(88, 33)
pal = self.findByType("paladin")
stepCounter = 0
while stepCounter < 6 and self.now()<30:
    stepCounter = stepCounter + 1
    for p in pal:
        palHeal(p, self.findFriends(), 0.5, True)
    self.move(Vector.add(self.pos, Vector(2, 0)))
    self.move(Vector.add(self.pos, Vector(-1,0)))

About your code: I suggest to keep it simple. See hints here

About missiles: see details here (TLDR: shell.targetPos)

Another tip is to instead of commanding a unit individually (and make a bunch of function calls) it might be better to “batch command” units with something like

def commandSoldiers(soldiers):
    for soldier in soldiers:
        # command archers

def commandArchers(archers):
    for archer in archers:
        # command archers

# secondary strategy for archers
def commandArchersOtherStrat(archers):
    for archer in archers:
        # command archers

def commandPaladins(paladins):
    for paladin in paladins:
        # command paladins

# then in the main loop
while True: # Very soon we can use real loop syntax
    friends = self.findFriends()
    soldiers = self.findByType("soldier", friends) # and archers and paladins
    commandSoldiers(soldiers)
    if someCondition: commandArchersOtherStrat(archers)
    else: commandArchers(archers)
    commandPaladins(paladins)
1 Like

UGH!

Well, I cleaned things up and made it to the Warlock fight. Had the troops positioned and was getting ready to code the warlock fight. I now can no longer load up Summit’s Gate without the tab crashing.

I am having the same problem now at the same place. However, the game crashes when loading the level now and I cant even fix my code. Is there any way to comment out my code manually, without needing to run it? (since it generates an infinite loop) I just want to be able to work on my code again

edit: now that i check, this is the same reason i haven’t completed The Trials yet either. If someone can teach us how to move past this it’d be enormously helpful!

You could try loading up the level in a different language, comment it out, and then reload the level in your normal programming language.

Thank you! That has allowed me to go back in, comment out the troubled sections, and do the work i needed to! Now i’m back to just having regular issues with the level

hi everyone,
Please ,can you share me your code trotod ?

Thank you

We don’t give out code as a regular policy. This website is meant to teach you, not give you answers.

I am so sad right now. After many hours and days and weeks trying to successfully complete Summit’s Gate I finally did it, first the two warlocks got overrun next the witch went down then finally, the chieftain was defeated. I raised my arms in VICTORY… and my browser crashed…
God hates me.