Bookkeeper (HELP NEEDED)


#1

Hi, I have been trying to pass this level and can’t pass it. Can you help me?

Here’s my code:

# Fight enemies for 15 seconds.
# Keep count whenever an enemy is defeated.
defeated = 0
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
        if enemy.health <= 0:
            defeated += 1
    if hero.time > 15:
        break

# Tell Naria how many enemies you defeated.
hero.moveXY(59, 33)
hero.say(defeated)

# Collect coins until the clock reaches 30 seconds.
item = hero.findNearestItem()

# Tell Naria how much gold you collected.
while True:
    hero.moveXY(58, 33)
    hero.gold
    hero.say("collected")

# Fight enemies until the clock reaches 45 seconds.
# Remember to reset the count of defeated enemies!
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

# Tell Naria how many enemies you defeated.
while True:
    pet.moveXY(59, 33)
    hero.say("defeated")

#2

Hi! The first part is ok, but you have to do the same with coins and the second wave of ogres.

F.e. here

“collected” is not defined. You even don’t need it, it coukd be just

hero.say(self.gold)


#3

All you need to do is implement the structure of you first while loop into the following item = hero.findNearestItem statement and while loop. The level asks you to fight for 15 seconds, which you’ve done with your

if hero.time > 15:
    break

statement.

It then requires you to collect gold for fifteen seconds. However you’ve only written item = hero.findNearestItem. If you repeat you first loop, but adapt it to deal with the task of collecting coins, and stopping when the clock reaches 30 seconds, that should work fine.

Finally you need to do the same thing for your last while loop, but, again, adapted to fight enemies, and stop when the clock reaches 45 seconds.

Hope this helps.


#4
  1. You haven’t made a variable for collected.
  2. Why say collected in quotation marks?
  3. Either say collected = hero.gold then hero.say(collected) or just say hero.say(hero.gold).
  4. to make it easier, just use a function, like this:fightAndReport(15)

#5

also why didn’t you just start with the default?
like this:

# This function allows to fight until the certain time
# and report about defeated enemies.
def fightAndReport(untilTime):
    defeated = 0
    while True:
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.attack(enemy)
            if enemy.health <= 0:
                defeated += 1
        if hero.time > untilTime:
            break
    hero.moveXY(59, 33)
    hero.say(defeated)

# Fight 15 seconds and tell Naria how many enemies you defeated.
fightAndReport(15)

# Collect coins until the clock reaches 30 seconds.


# Tell Naria how much gold you collected.
hero.say(hero.gold)

# Fight enemies until the clock reaches 45 seconds.
fightAndReport(45)


#6

You just say “collected” and “defeated” instead of the variables. And yeah, if you dont have a boss star, just use hero.gold if avaible


#7

I’m not sure if I fixed it correctly, let me know.:blush:

Here’s my code:

# Fight enemies for 15 seconds.
# Keep count whenever an enemy is defeated.
defeated = 0
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
        if enemy.health <= 0:
            defeated += 1
    if hero.time > 15:
        break

# Tell Naria how many enemies you defeated.
hero.moveXY(59, 33)
hero.say(defeated)

# Collect coins until the clock reaches 30 seconds.
while True:
    item = hero.findNearestItem()

# Tell Naria how much gold you collected.
while True:
    hero.moveXY(59, 33)
    hero.say("hero.gold")

def fightAndReport(untilTime):
    defeated = 0
    while True:
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.attack(enemy)
            if enemy.health <= 0:
                defeated += 1
        if hero.time > untilTime:
            break
    hero.moveXY(59, 33)
    hero.say(defeated)

# Fight 15 seconds and tell Naria how many enemies you defeated.
fightAndReport(15)

# Collect coins until the clock reaches 30 seconds.
findAndReport(30)

# Tell Naria how much gold you collected.
hero.say(hero.gold)

# Fight enemies until the clock reaches 45 seconds.
fightAndReport(45)

#8

you just defined what hero.findNearestItem() is. but you didn’t say to collect it, and because there is no break, you will stand in place forever

without quotation marks

you didn’t say this.


#9

Here’s my new code:

# Fight enemies for 15 seconds.
# Keep count whenever an enemy is defeated.
defeated = 0
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
        if enemy.health <= 0:
            defeated += 1
    if hero.time > 15:
        break

# Tell Naria how many enemies you defeated.
hero.moveXY(59, 33)
hero.say(defeated)

# Collect coins until the clock reaches 30 seconds.
while True:
    item = hero.findNearestItem()
    if item:
        pos = item.pos
        x = pos.x
        y = pos.y

# Tell Naria how much gold you collected.
while True:
    hero.moveXY(59, 33)
    hero.say(hero.gold)

def fightAndReport(untilTime):
    defeated = 0
    while True:
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.attack(enemy)
            if enemy.health <= 0:
                defeated += 1
        if hero.time > untilTime:
            break
    hero.moveXY(59, 33)
    hero.say(defeated)

# Fight 15 seconds and tell Naria how many enemies you defeated.
fightAndReport(15)

# Collect coins until the clock reaches 30 seconds.
findAndReport(30)

# Tell Naria how much gold you collected.
hero.say(hero.gold)

# Fight enemies until the clock reaches 45 seconds.
fightAndReport(45)

#10

If it ain’t broke, don’t fix it

You have a successful pattern, just follow it:
#################################

defeated = 0
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
        if enemy.health <= 0:
            defeated += 1
    if hero.time > 15:
        break
hero.moveXY(59, 33)
hero.say(defeated)

###################################

while True:
# your code
        y = pos.y
# Where do you collect coins?
# Where do you exit the loop?

Then you tell Naria how much gold you collected but why in a “while True” loop? See how you did it when fighting enemies.
Then your function fightAndReport isn’t needed. Simply follow the initial pattern while not forgetting to zero the defeated enemies and to change the hero.time


#11

right now, you would be standing in 59, 33 staring at Naria and saying quietly That coin is over there, that one is there, a diamond is right there, and NO! an ogre! but How do I deal with it… anyway, that coin is there, that one is there…