Every NAN seconds

Discussion and feedback on Construct 2

Post » Thu Oct 22, 2015 5:36 pm

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.
B
11
S
3
G
1
Posts: 98
Reputation: 1,062

Post » Thu Oct 22, 2015 7:06 pm

Thank you for sharing your solution.
B
135
S
33
G
17
Posts: 1,560
Reputation: 20,734


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 8 guests