My code breaks Chrome. Why?

0 favourites
  • 4 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • So I have this code in my game:

    What I think it should do: While the bool IsArmageddon is true, it should repeat those actions. In other words, it should wait 0.5 seconds, apply the impulse, subtract one from the variable, and repeat. Wait 0.5 seconds again, apply impulse again, etc until the variable hits 0.

    What it does: Brutally murders Chrome. Chrome completely locks up as soon as that variable goes over 100.

    So, I get that I'm doing something wrong. Probably. I just want to know WHY it's wrong. Is this like an endless loop kind of thing? Or is there a small chance that this is actually a bug?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • while loop won't be paused by action wait, it only pend a task for each action wait.

    Thus, "it should wait 0.5 seconds, apply the impulse, subtract one from the variable, and repeat..." is not correct.

  • Several things:

    Wait does not block! This is important to understand.

    While is very dangerous - that event will kill your game if that condition is not cleared quickly, which it is not.

    Don't put your Armageddon toggles at the top level, place them right after you change the countdown, otherwise they constantly run, when they only need to run when the value actually changes.

    Use the Timer behaviour to manage your wait cycle. When IsArmageddon is set to true, start your timer. In On timer, do your physics and countdown code, and check your flag. If the flag is still true, trigger the same timer.

  • Thanks guys! I learn something new every day. Still a noob when it comes to loops.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)