Stopwatch in tiny dungeons

I have a stopwatch in my tiny dungeons game, to count up the time. I do this by increasing a variable that is the total seconds. (note: I do not want to use time since start, so I can pause and do other stuff.) I have a problem with the stopwatch when the time gets to an even minute. You can see this here, when the mods were playing it.


This is my code

I needed a divmod so I used remainder to keep my remainder, then (total - remainder) / 60 to get the minutes.
If anybody could help me with that rounding error that would be great.
@WoofWoof do you know what might be causing this?
Also if anyone has way of optimising this code that would be great.

2 Likes

I have a stopwatch extension that you could take a look at here, in case it’s helpful.

3 Likes

From briefly skimming over this, you seem to do mostly the same thing as me. I might use that next time, would have saved me a lot of effort. It is good to try it yourself without an extension the first time, just so you know you can do it and you aren’t cutting corners. Before hand I was trying to do this with milliseconds, but it slowed down the game a lot. I might try to solve this right now, I have a few ideas. (It must be nice to be able to instantly post)

lol I saw this issue while playing the game a few times. Just looking at your code, when the (remaining time / 60) has a remainder of 0, you skip updating the “remainder” variable. Then inevitably, since the remainder variable is still set to whichever number it was at the last time you died, that “time - remainder” block will not be evenly divisible by 60 and will result in a number with a lot of decimals that fill up the screen. I am willing to bet that just removing that IF block (without removing the code inside of course) would fix your issue.

Side note, why do those “time left” and “seconds” variables even exist? They are both equal to “remainder” anyways!

1 Like

I had milliseconds and hours as well, when I was done with seconds and minutes they couldn’t just be all time left. The code is messy because it went through a lot of stuff. I will try fixing the remaining time error. Thanks :slight_smile:

1 Like