Creating a "MM:SS" style clock with one event

2

Stats

1,477 visits, 1,817 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 28 Jan, 2018. Last updated 19 Feb, 2019

Based on the method by strevor73

I've seen a few tutorials on how to do this but they all use multiple objects or variables. It's possible to do this however with just one variable and one event.

The first action adds 1 to the timer. Please note that whilst you can just add 1, using "dt * 60" will use delta time (a fancy way of saying it accounts for lag).

Then comes converting the time into a "mm:ss" format (minutes:seconds).

To do this, we set the text to:

floor(Clock/60) & ":" & floor((Clock%60)/10) & floor(Clock%10)

Let's break it down:

floor(Clock/60)

Displays the minutes. By dividing by 60 we get a number that will increase by 1 every 60 intervals.

floor((Clock%60)/10)

The "%" sign gives us the remainder, so basically everything left over that isn't divisible by 60. This would give us the seconds. However, by dividing by 10 and removing anything past the decimal, we only get the 10s.

floor(Clock%10)

Gives us the remainder of everything but the 10s. Uses floor() to remove delta time inaccuracies. Displays the single digit seconds.

That's pretty much all there is. It's worth noting you may want to set the default text to "0:00". Additionally, using "every X seconds" will not reset on it's offset, so if you need precise resetting time I'd recommend the timers behavior.

That's everything, hope it helps.

Edit

Added floor() to the seconds do incorporate delta time.

  • 4 Comments

  • Order by
Want to leave a comment? Login or Register an account!