0 Favourites

How do I blend this codes together?

  • Ok, so my goal is to have a countdown timer that starts on 02:00:00 (that's two minutes) and go all the way to 00:00:00.

    My timer is currently on dt subtraction every tick from a global variable of 120. That's why I'm using floor(Timer/60) & ":" & Timer%60 to show it like a real number. However, instead of showing 01:05:34, it is currently showing 1:5.34874. I need to blend the timer code with two more lines/principles.

    1) The zeropad, so I put zeroes and make the timer always have 6 digits (in other words, 02:00:00 instead of 2:0.

    2) Make the code show the last two digits and no digit else. So basically have the 01:05:34 instead of 01:05:34238723. I thought that I had to use the round(N*x/x) to have that work. However, I need the system to interpret this as a number by itseft, as the floor(Timer/60) & ":" & Timer%60 basically has two independent numbers (because, basically, I need it to show 02:00:00 instead of 02:00



    Can you guys help me out?

  • Ok so you want a timer with fixed leading 0s if necessary and with significant figures up to centiseconds (1/100 of a second).

    The timer gives the time in seconds in decimal format, with more sig figs than you need. So you'll need to round to the nearest centisecond - round(100*Timer). Then use the text object's APPEND action to add each digit you need, in addition to modulo which you seem to already know how to use.

    Start with setting a variable with the total current time in centiseconds

    Set text to (how many 10 minutes do I have? 10 minutes = 60,000 centiseconds, can be 0), subtract that from your variable

    Append text (how many minutes are left? 1 minute = 6,000 centiseconds), subtract that from variable

    Append ":"

    Append (10 seconds=1,000 centiseconds), subtract from variable

    Append (1 second = 100 centiseconds), subtract...

    Append ":"

    Append (10 centiseconds), subtract..

    Append (whatever is left)

    Hmm made sense when I wrote it, but now I look back and it might be kinda confusing. I can put together a capx later if you have trouble.

    Edit: Looks like I didn't need modulo after all. Or maybe it will look cleaner if it is used? Or something...

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Gee man!

    Your code not only works like a charm, but I also don't think I'll ever have problem with timers/countdowns again. Your code + your explanation made me truly understand it. I've even played and experimented with it a little bit already.

    Thank you!

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