How do I format a count down timer with trailing zero

0 favourites
  • 13 posts
From the Asset Store
“Zero Numbers” is a logic game. Game with Source-Code (Construct 3 / .c3p) + HTML5 Exported
  • Hi all together,

    in my game I want to display a count down timer. It counts from 30.0s down to 0.0s

    The deciseconds always must be displayed but what I'm getting is a missing ".0" at

    30, 29, 28, ... 3, 2, 1 and 0 seconds - so it looks like:















    Every tick I calculate the variable gTimeLeft to display how much time is left.

    • using round(gTimeLeft*10)/10 cuts off the required ".0"
    • zeropad() is only usefull for adding leading zeros, but I need a trailing zero including the decimal point

    So how can I format my timer like "ss.s" without slowing down the frame rate?

    Thanks for hints and/or solutions in advance.

  • good idea

    working with "Set text to left(text.ivTimerText,4) " combined with a little adjustment for my special needs does the formatting trick.

    Thank you.

    by the way:

    I didn't even think of using a timer behavior! This is much more convenient then my awkward try with calculating the time left within the condition "System | Every tick" .

    I can imagine that using a timer like you did, is more resource-friendly then my way with "System | Every tick". What do you think?

  • uuups, I just noticed a big drawback with RamPackWobble's timer solution

    When I count down from 30s to 0 it will take about 33s !!! It is 3s to slow !

    I tested this on different PCs with the same result - what's wrong ?

    I need a really accurate timer, so what to do?

    Any help is appreciated.

  • I will have a play and get back to you - obviously not the best method then ! But in my defence I was more interested in getting the formatting right, but still no good as it stands - "I'll be back..."


    Back Give this a try - it will still not be 100%.

    If the updated capx (previous posted one updated) if still no good let me know and I will try with wallclock...

    edit 2

    I added a silly loop to randomly rotate quite a few largish sprite to deliberately slow down my computer (from 60 fps to about 28 fps). with this loop running a five minute countdown took 302 seconds without the loop it took 300.043 seconds. Obviously using every tick take the dt from a counter allows for a slight error - this error is greater the higher the dt.

  • You don't have to defend yourself, you helped me with the original problem (the formatting)

    The time delta / delay is more a kind of sideshow, but I'd be glad to get this problem solved.

    Tomorrow I'll give your new capx a try ...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I played with the code and tried a few things.

    Your built-in slow down mechanism is very usefull for testing - thanks for sharing

    Looks like your code works as a really good count down timer regardless of the resulting FPS.

    I wasn't aware of the big difference between "wallclocktime" and "time" for setting the variable gvStartTime.

    If "time" is used instead of "wallclocktime" the count down time differs badly from the real world time.

    After reading several posts regarding time/timer topics I still don't no how to use "timescale" in a usefull way.

    Can you give me an example or explanation?

  • hey braingame i think u solved ur problem by now, if u dident, try this , no time clocks needed just 3 numbers or 2 let me think.... ok so u want to show 30.9 seconds lets say why dont u substract for a countdown (from the time 0.1 every 0.1 construct will automatically show u the .N decimals if does show u more then 1 decimals then ur math uses some imperative format like 1.23 * by something or / by something try keep round numbers 1 and 2 ussualy works ... how ever wanted to ask, im doing a game and i want all the decimals to disapear even the " . " cant figure how the hell am i supposed to do that in construct 2 , i found the round number format just i dont really understand how to apply it to my game, basically my problem is when i buy 1 item the next purchase of that item will be (item.price * 1.20 ) now the decimal doesnt show for about 3 purchases after that .N , .NN, .NNNN appears so need to fix it cause i have high priced items that are in millions and billions , so i can imagine the .decimals on those

  • how ever ur problem is confusing cause every tick value differes then any other engines, some are 0.001 responses some are bigger, so not sure what the tick value u have there u should change the everytick event to exactly when u want to change the time then ur .Decimal will be solved if every tick is less then what u imput cause if its not the construct2 engine doesnt do faster responses and calculations then everytick thats the fastest response ul get as an example

    If everytick value is 0.002 you wont be able to say every 0.001

    in order to find out the every tick value you should ask Tom or Ashley or find someone that precisly knows that value

  • Simple timer

  • Hi RamPackWobble

    Do you still have the capx file? If yes, could you upload it again, please? I need to use wallclock and show it separately in minutes and seconds. Thanks in advance.

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