Feedback: Bookkeeper


#1

It was not immediately obvious that I had to be standing close to the archer in order to report the number. There is a cross, but it wasn’t mentioned explicitly.
It’s also possible to get away with not collecting any coins and reporting 0 afterwards. Was that intentional?
Goal failure if Naria dies: works.

There was also this from the first submission seed:


Saying NaN didn’t work either. This issue didn’t happen on any of my other submissions.

Edit: the code from the editor shows that Naria is supposed to say “Eh? Come closer if you’re talking to me!” if the speaker is too far away, but that never happened.


Bookkeeper Help : Something Wrong With My Code
#2

Absolutely agree.
My check was very simple: I go to Naria and keep saying “0” .
So it was very easy to pass the level.

Still IMHO it’s reasonable to add to the description that player need not only say but also go closer to Naria.


#3

I also didn’t get closer the first time, but then saw the big X.

I managed to beat the level the correct way, but there was an issue is with infinite loops.

count = 0
while self.now() <= 15:
    enemy = self.findNearest(self.findEnemies())
    if enemy:
        while enemy.health > 0:
            self.attack(enemy)
        count += 1

Will fail due to hitting the max process limit. This can be fixed with simply adding

else:
    self.say('waiting')

but that will not be obvious to the students. You may need to write the first one out and have students do the next two.


#4

I’ve experienced the same problem as @Hinkle, hitting the maximum execution limit due a “seemingly infinite loop” that was actually correct code.

Adding a wait(1) or say('') call in the else works around the issue, but I believe this should be addressed in the level design or in the game engine.


#5

The method I used, which also appears in the guide, is to use a break:

while(true) {
    // do things
    if(this.now() >= 30) {
        break;
    }
}

For some reason, while(this.now()<30) results in an infinite loop but the above method doesn’t. It happens in other levels too. I remember encountering this when I wanted to shield for the first x seconds of a level.
I think people are more likely to try this first (like I did) because it seems more intuitive. Then they get stumped by the infinite loop. The guide, at least, shows a workaround, but could we get an explanation for why the more obvious approach doesn’t work?


#6

There is a hidden patch affecting the way the game engine interprets your code: a basic game frame is advanced in the main loop if time was not advanced. Basically

loop {
...
}

is equivalent to:

while (true) {
.....
if no_wait_or_time_taking_hero_actions_performend
    this.wait(one_game_frame);
}

So a loop may work but a while(true) will fail.
This protection is implemented to help beginners and it may not be activated on all levels.
Basically your code was bad all the time, but the compiler “fixed” it.


#7

@AdrianCgw is right except both loop: and while True: wait one frame before updating (while true was added due to it being the favored code loop code for courses)

while not False:
while 1 is 1:
while self.now() < 30:
while (anything but the word: True):

will update as fast as it can, which can lead to the max process being hit, as computers can do things really fast.

There is a forum post either here or on GitHub about this. I would link to it, but I can’t find it.


Bookkeeper help!
#8

if you use enemy.health to see if an enemy has died, it says i need this.health. but this. health tracks my health not the enemy’s health. It just won’t let me continue.


#9

Here you go.

Try checking your whole code, the fix suggestions are not very accurate. Did you define enemy correctly and is it not null/None?


#10

i figured it out im supposed to put a if(enemy){} around it


#11

Hello , I do not understand why when I see Naria , my character gives 0 instead of the number of enemy killed.

loop:

enemy = self.findNearestEnemy()
defeated =0

if enemy:
    self.attack(enemy)
    if enemy.health <= 0:
        defeated += 1
if self.now() > 15:
    self.moveXY(59, 33)
    self.say("voici le nombre d'enemy tuer : "+defeated)
    break

Thanks for your help.


#12

You have this instruction inside the loop:

defeated = 0

so each time the loop is run again defeated is set back to 0


#13

Thank you again it’s more easiest than that


#14

What’s wrong with my collected :frowning: ?

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

Collect coins until the clock reaches 30 seconds.

while True:
item = hero.findNearest(hero.findItems())
collected = 0
if item:
hero.move(item.pos)
collected += 1
if hero.now() > 30:
break
hero.moveXY(59, 33)
hero.say(collected)

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