Every NAN seconds

0 favourites
  • 2 posts
From the Asset Store
Like tourists, Travel around the world as fast as you can!
  • So I recently came across a big in the game that I'm programming and I figured it out, but I thought I would post my results here since the behavior isn't exactly intuitive.

    What happened was I had a player who automatically shoots every x seconds when they're alive, but I also wanted to allow the player to upgrade their shooting speed, so I have an event which looks sort of like this:

    Every 2.5/Player.Speed seconds, Player shoots their preferred weapon type.

    This worked great for me, but later I added functionality to restart the layout after the player is destroyed, however I ran across a problem, the player would never shoot once the layout was restarted. After a little testing I figured out why this was. After the player is destroyed, the event above tried to activate and calculated that it should happen every 2.5/0 = NAN seconds, so it stopped, permanently.

    To fix this I added an extra condition:

    for each Player, every 2.5/Player.Speed seconds, player shoots their preferred weapon type.

    This way, after the player is destroyed, the event is never called, so it never sets itself to stopping permanently. Now, I can restart the layout and the player will still shoot.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for sharing your solution.

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