Undefined is not an object (evaluating 'f.start') error SOLVED


#1

There is an error and I doesn’t highlight a line for me and I can’t see what is wrong.

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.

def griffinMovement(gr):
    for r in range(len(gr)):
        g = gr[r]
        enemy = hero.findNearestEnemy()
        if enemy and enemy.type == "fangrider":
            hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "catapult":
            hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "orge":
            hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "thower":
            hero.command(friend, "move", ( {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "scout":
            hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "munchkin":
            hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy:
            hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)

def archerMovement(ar):
    for r in range(len(ar)):
        a = ar[r] 
        enemy = hero.findNearestEnemy()
        if enemy:
            global h
            if enemy.type == "fangrider":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "thower":
                hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "munchkin":
                hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "scout":
                hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "orge":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "catapult":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy:
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)

def soldierMovement(so):
    for o in range(len(so)):
        friend = so[o]
        target = hero.findNearestEnemy()
        if target:
            global h
            if target.type == "scout":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "munchkin":
                hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "thower":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "orge":
                hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "catapult":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            else:
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
                
                

def stuff():
    for i in range(len(friends)):
        friend = friends[i]
        global archers
        global soldiers
        global griffinRiders
        if friend.type == "archer":
            archers.append(friend)
        if friend.type == "soldier":
            soldiers.append(friend)
        if friend.type == "griffin-rider":
            griffin.append(friend)

def heroFuntions():
    enemies = hero.findEnemies()
    enemy = hero.findNearestEnemy()
    flagGreen = hero.findFlag("green")
    flagBlack = hero.findFlag("black")
    if hero.isReady("regen") and hero.health < hero.maxHealth/2:
        hero.cast("regen", hero)
    if flagGreen:
        if enemy:
            hero.attack(enemy)
    if flagBlack: 
        if flagGreen:
            hero.removeFlag(flagGreen)
        hero.pickUpFlag(flagBlack)

while True:
    friends = hero.findFriends()
    archers = []
    soldiers = []
    griffin = []
    stuff()
    if hero.time % 2 == 0:
        h = 5
    else:
        h = -5
    griffinMovement(griffin)
    if hero.time % 2 == 0:
        h = 5
    else:
        h = -5
    soldierMovement(soldiers)
    if hero.time % 2 == 0:
        h = 5
    else:
        h = -5
    archerMovement(archers)
    heroFuntions()
    
    if hero.gold >= hero.costOf("griffin-rider") and hero.findFlag("violet"):
        hero.pickUpFlag(hero.findFlag("violet"))
        hero.summon("griffin-rider")

#2


#3

Did you define “friend” in griffinMovement?

hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})


#4

Yes I did not define friend but even when I replaced it with the right variable the error still pops up.

New code:

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.

def griffinMovement(gr):
    for r in range(len(gr)):
        g = gr[r]
        enemy = hero.findNearestEnemy()
        if enemy and enemy.type == "fangrider":
            hero.command(g, "move", {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "catapult":
            hero.command(g, "move", {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "orge":
            hero.command(g, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "thower":
            hero.command(g, "move", ( {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "scout":
            hero.command(g, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "munchkin":
            hero.command(g, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy:
            hero.command(g, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)

def archerMovement(ar):
    for r in range(len(ar)):
        a = ar[r] 
        enemy = hero.findNearestEnemy()
        if enemy:
            global h
            if enemy.type == "fangrider":
                hero.command(a, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "thower":
                hero.command(a, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "munchkin":
                hero.command(a, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "scout":
                hero.command(a, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "orge":
                hero.command(a, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "catapult":
                hero.command(a, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy:
                hero.command(a, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)

def soldierMovement(so):
    for o in range(len(so)):
        friend = so[o]
        target = hero.findNearestEnemy()
        if target:
            global h
            if target.type == "scout":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "munchkin":
                hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "thower":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "orge":
                hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "catapult":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            else:
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
                
                

def stuff():
    for i in range(len(friends)):
        friend = friends[i]
        global archers
        global soldiers
        global griffinRiders
        if friend.type == "archer":
            archers.append(friend)
        if friend.type == "soldier":
            soldiers.append(friend)
        if friend.type == "griffin-rider":
            griffin.append(friend)

def heroFuntions():
    enemies = hero.findEnemies()
    enemy = hero.findNearestEnemy()
    flagGreen = hero.findFlag("green")
    flagBlack = hero.findFlag("black")
    if hero.isReady("regen") and hero.health < hero.maxHealth/2:
        hero.cast("regen", hero)
    if flagGreen:
        if enemy:
            hero.attack(enemy)
    if flagBlack: 
        if flagGreen:
            hero.removeFlag(flagGreen)
        hero.pickUpFlag(flagBlack)

while True:
    friends = hero.findFriends()
    archers = []
    soldiers = []
    griffin = []
    stuff()
    if hero.time % 2 == 0:
        h = 5
    else:
        h = -5
    griffinMovement(griffin)
    if hero.time % 2 == 0:
        h = 5
    else:
        h = -5
    soldierMovement(soldiers)
    if hero.time % 2 == 0:
        h = 5
    else:
        h = -5
    archerMovement(archers)
    heroFuntions()
    
    if hero.gold >= hero.costOf("griffin-rider") and hero.findFlag("violet"):
        hero.pickUpFlag(hero.findFlag("violet"))
        hero.summon("griffin-rider")


#5

I also noticed in griffinMovement and archerMovement that you didn’t define “target”


#6

Changing that did not fix the problem but thank you. That is weird though because that code was running even before.

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.

def griffinMovement(gr):
    for r in range(len(gr)):
        g = gr[r]
        target = hero.findNearestEnemy()
        if enemy and enemy.type == "fangrider":
            hero.command(g, "move", {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "catapult":
            hero.command(g, "move", {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "orge":
            hero.command(g, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "thower":
            hero.command(g, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "scout":
            hero.command(g, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy and enemy.type == "munchkin":
            hero.command(g, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)
        elif enemy:
            hero.command(g, "move",  {"x":target.pos.x + h,"y": target.pos.y})
            hero.command(g, "attack", enemy)

def archerMovement(ar):
    for r in range(len(ar)):
        a = ar[r] 
        target = hero.findNearestEnemy()
        if enemy:
            global h
            if enemy.type == "fangrider":
                hero.command(a, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "thower":
                hero.command(a, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "munchkin":
                hero.command(a, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "scout":
                hero.command(a, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "orge":
                hero.command(a, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy.type == "catapult":
                hero.command(a, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)
            elif enemy:
                hero.command(a, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(a, "attack", enemy)

def soldierMovement(so):
    for o in range(len(so)):
        friend = so[o]
        target = hero.findNearestEnemy()
        if target:
            global h
            if target.type == "scout":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "munchkin":
                hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "thower":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "orge":
                hero.command(friend, "move", {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            elif target.type == "catapult":
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
            else:
                hero.command(friend, "move",  {"x":target.pos.x + h,"y": target.pos.y})
                hero.command(friend, "attack", target)
                
                

def stuff():
    for i in range(len(friends)):
        friend = friends[i]
        global archers
        global soldiers
        global griffinRiders
        if friend.type == "archer":
            archers.append(friend)
        if friend.type == "soldier":
            soldiers.append(friend)
        if friend.type == "griffin-rider":
            griffin.append(friend)

def heroFuntions():
    enemies = hero.findEnemies()
    enemy = hero.findNearestEnemy()
    flagGreen = hero.findFlag("green")
    flagBlack = hero.findFlag("black")
    if hero.isReady("regen") and hero.health < hero.maxHealth/2:
        hero.cast("regen", hero)
    if flagGreen:
        if enemy:
            hero.attack(enemy)
    if flagBlack: 
        if flagGreen:
            hero.removeFlag(flagGreen)
        hero.pickUpFlag(flagBlack)

while True:
    friends = hero.findFriends()
    archers = []
    soldiers = []
    griffin = []
    stuff()
    if hero.time % 2 == 0:
        h = 5
    else:
        h = -5
    griffinMovement(griffin)
    if hero.time % 2 == 0:
        h = 5
    else:
        h = -5
    soldierMovement(soldiers)
    if hero.time % 2 == 0:
        h = 5
    else:
        h = -5
    archerMovement(archers)
    heroFuntions()
    
    if hero.gold >= hero.costOf("griffin-rider") and hero.findFlag("violet"):
        hero.pickUpFlag(hero.findFlag("violet"))
        hero.summon("griffin-rider")


#7

One thing I forgot to mention is that the error appeared when I added the code

hero.command(g, "move", {"x":target.pos.x + h,"y": target.pos.y})

to the program. I do not see what is wrong with it.


#8

Maybe try defining “h”, since it doesn’t look like you defined it at all in the function.


#9

Thank you I have solved the problem but it took a while there were a lot of errors that just built up on each other. Thank you.


#10

Please do not post working code, or else others will copy it off without really learning :slight_smile:


#11

Sorry, and thank you for telling me.