Backwoods Treasure - Help in Python


    enemies = self.findEnemies()
    enemyIndex = 0
    coins = self.findItems()
    coinIndex = 0
    self.moveXY(53, 18)

    while len(enemies) > enemyIndex:
        enemy = enemies[enemyIndex]
        enemyIndex += 1
        if enemy:
            while > 0:
                if self.isReady("power-up"):
                elif self.isReady("bash"):
    while len(coins) > coinIndex:
        coin = coins[coinIndex]
        coinIndex += 1
        if enemies:
        if coin:
            self.moveXY(coin.pos.x, coin.pos.y)

I’ve been trying to make my hero stop grabbing coin and attack an enemy if there is one but he either attacks only enemies or grabs coins. I’ve tried using distanceto, if not enemy, and a few other attempts. Any ideas?


The code you have above does:

– get enemies and coins
– kill all enemies until there are no more
– (then) pick up all coins until there are no more
– (never loops back to enemies since there are probably always coins)

make it:

– get Nearest-enemy and Nearest-coin
– if enemy attack
–else if coin pick up

then it will attack if there are enemies and get coins otherwise . . . one at a time

you could also make the first if a “if enemy and distance < #” then it will pick up coins until they get close…


my code always says to switch the item x and y to my hero’s x and y, how do i fix it?


We would have to see the code to understand the exact nature of the error?

which command,