0 Favourites

Every NAN seconds

  • 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.

  • Construct 3

    Buy Construct 3

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

    Buy 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)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
198 18,662
Tom's avatar
Tom Construct Team Founder
Unread hot topic
98 7,596
norum82's avatar
Unread hot topic
74 4,514
Dalal's avatar