Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Funny mistake in Chapter 5: class Totem #8

Open
PeterLeikauf opened this issue Jan 27, 2019 · 0 comments
Open

Funny mistake in Chapter 5: class Totem #8

PeterLeikauf opened this issue Jan 27, 2019 · 0 comments

Comments

@PeterLeikauf
Copy link

PeterLeikauf commented Jan 27, 2019

Hi Guys

the original code conrtains a funny, non-reproducible, but regular bug!

Here is the original code:

class Totem extends TileSprite {

  ....

  update(dt, t) {
    if (math.randOneIn(250)) {
      this.fireIn = 1;
    }
    if (this.fireIn > 0) {
      this.fireIn -= dt;
      // Telegraph to the player
      this.frame.x = [1, 0][((t / 0.1) | 0) % 2];
      if (this.fireIn < 0) {
        this.fireAtTarget();
      }
    }
  }
}

Now here's what happens form time to time: By sheer coincidence, fireIn might end up exactly as zero after a couple of frames (around 60). In that case, no bullet will be fired (because fireIn < 0 is false) and no further subtraction will occur (because fireIn > 0 is also false). Happens regularly on my mac with Safari ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant