Timer for Bash 'em All

Hey,

The Bash 'em All level requires the use of bash. My shield has a 6 second cycle period. In order to “Bash 'em All”, I had to wait 6 seconds between attacks.

I set up the following loop, and it worked. Is there a better solution?

while enemyIndex < len(enemies):
    enemy = enemies[enemyIndex]
    if self.isReady("bash"):
        self.bash(enemy)
        enemyIndex += 1
    else:
        enemyIndex = enemyIndex
    self.moveXY(40, 33)

Thanks,
George34

I set up an alternative timer using self.now. I think that this solution uses fewer resources, but I’m not really sure.

while enemyIndex < len(enemies):
    enemy = enemies[enemyIndex]
    if self.isReady("bash"):
        self.bash(enemy)
        timer = self.now()
        count = self.now()
        while timer - count <= 6:
            count = self.now
        enemyIndex += 1

Looking at it, again, I don’t think this should have worked. “count” is continuously growing, so “timer - count” should have returned a negative number, the condition should failed on the first iteration. One of the functions is returning an absolute value.

That second while loop looks like it should result in an infinite loop, but you’re implying that it passed?

If you wanted to wait 6 seconds, you could also try self.wait()

And is there any need for enemyIndex = enemyIndex?

Actually, I;m stating that it passed.

I didn’t know about self.wait()

enemyIndex = enemyIndex is the key( I think) to making the timer in the first loop I tried. The first if executes when bash is ready, and enemyIndex only increments after bash is ready. If the “if bash is ready” statement doesn’t execute, I need to catch the loop and preserve my place in the arrary, so I used “enemyIndex = enemyIndex”. Without the else statement, I would have fallen out of the loop and only attacked once.