Hi, I wanted to ask if anyone could help with the coding I have to enable my hero to pick up a flag.
# Be the first to 100 gold!
# If you are defeated, you will respawn at 67% gold.
while True:
# Find coins and/or attack the enemy.
# Use flags and your special moves to win!
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
hero.attack(enemy)
hero.attack(enemy)
hero.attack(enemy)
item = hero.findNearestItem()
flag = hero.findFlag("green")
if flag:
flagPos = flag.Pos
hero.movexy(flag.pos.x, flag.pos.y)
hero.pickUpFlag(flag)
hero.findNearestItem()
if item.type == "coin":
hero.moveXY(item.pos.x, item.pos.y)
I see that when I activate the code a bit into the level the enemy dies but my code has a problem with the attacking because there are 4 of the same lines and my hero won’t do anything after.
I now just noticed that when I place a black flag I get an undefined error for the word “Item”
# Be the first to 100 gold!
# If you are defeated, you will respawn at 67% gold.
while True:
green = hero.findFlag("green")
black = hero.findFlag("black")
enemy = hero.findNearestEnemy()
if green:
hero.pickUpFlag(green)
hero.findNearestEnemy()
hero.attack(enemy)
if black:
hero.pickUpFlag(black)
hero.findNearestItem()
if item.type == "coin":
hero.moveXY(item.pos.x, item.pos.y)