Bookkeeper Help : Something Wrong With My Code

If your loop takes zero frames to execute, it will execute indefinitely preventing the game from advancing. That is, your code will be stuck running in the same game frame forever with the same outcome in all iterations.

That is because CodeCombat’s interpreter applies special treatment to the loop: and while True: constructs—if an iteration takes zero frames to execute, the interpreter will automatically wait for the next game frame before running the next iteration. You can read more about this in this GitHub issue.

This also means that the “automatically wait for next game frame” behavior is only applied when you explicitly input loop: or while True:, not when the while condition expression evaluates to true (e.g. while 1==1:, while self.now() < 9000: etc) which can then result in an infinite loop that may prevent the game state from advancing if all loop iterations take zero frames to execute.

I believe this is all very tricky for the target audience which is people that are learning to code. Even regular contributors like @zuf didn’t know about these intricacies. In my humble opinion, the game engine should handle this problem so the players don’t need to. But, in fact, this is pretty tricky to do as it may result in an unwanted delay in your loops, as you can see from the comments in the linked issue.

I also found that several people (including me!) have run into this issue while playing the Bookkeper level, as you can see in the relevant thread.

Perhaps it is time to try to address this, or maybe this will be solved by the new interpreter that is in the works?
/cc @nick