How do I format a count down timer with trailing zero

Get help using Construct 2

Post » Sat Mar 01, 2014 2:54 pm

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:

30
29.9
29.8
29.7
29.6
29.5
29.4
29.3
29.2
29.1
29
28.9
29.8
...

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.
B
15
S
4
G
3
Posts: 52
Reputation: 1,513

Post » Sat Mar 01, 2014 7:39 pm

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Sun Mar 02, 2014 12:21 pm

good idea :D

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?
B
15
S
4
G
3
Posts: 52
Reputation: 1,513

Post » Sun Mar 02, 2014 7:00 pm

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.
B
15
S
4
G
3
Posts: 52
Reputation: 1,513

Post » Sun Mar 02, 2014 7:06 pm

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..."

edit

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.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Sun Mar 02, 2014 9:24 pm

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

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 ...
B
15
S
4
G
3
Posts: 52
Reputation: 1,513

Post » Sun Mar 02, 2014 11:43 pm

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Thu Mar 06, 2014 9:30 pm

I played with the code and tried a few things.
Your built-in slow down mechanism is very usefull for testing - thanks for sharing :D
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?
B
15
S
4
G
3
Posts: 52
Reputation: 1,513

Post » Fri Feb 06, 2015 1:10 am

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
B
78
S
23
G
69
Posts: 1,353
Reputation: 44,005

Post » Fri Feb 06, 2015 1:12 am

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
B
78
S
23
G
69
Posts: 1,353
Reputation: 44,005

Next

Return to How do I....?

Who is online

Users browsing this forum: UberLou and 10 guests