Timer run in background

Get help using Construct 2

Post » Tue Jun 06, 2017 7:19 pm

Someone could tell me how can you go get a timer in the background? Ie when the player switches off the game the time continues to flow. For example I touch a button in the game and it is written that to complete the upgrade it takes 15 minutes and if I leave the game the time continues.
B
14
S
7
Posts: 17
Reputation: 1,238

Post » Tue Jun 06, 2017 7:26 pm

That's pretty complicated to pull off, you can safe the current time of the game to a global variable which you will keep on local storage, when the player starts the game again check the current time and compare it with the one stored in the local storage and make a substract function. See this on how to get the current time.

https://www.scirra.com/tutorials/940/ho ... -a-project
Like my work? Fallow me on social media, and see my games on the arcade.
B
7
S
5
G
9
Posts: 298
Reputation: 5,367

Post » Tue Jun 06, 2017 7:34 pm

I had tried to use Rex's TimeAwayL plugin but I can not figure out how to stop time for example when it comes to 10:00 minutes it has to stop and then how to make the text so 00:00 instead of the default 0.000.
B
14
S
7
Posts: 17
Reputation: 1,238

Post » Tue Jun 06, 2017 7:42 pm

I haven't used that plugin so far, maybe they are some tutorials available on the site.

Btw they are more problems to tracking time, because usually it uses your local time, which you can easy change to manipulate the game. So best solution would be to track some server time instead. I haven't implemented anything like that so far but one thing I know its pretty complicated so you will have to do tons of research on various topics to get it done.
Like my work? Fallow me on social media, and see my games on the arcade.
B
7
S
5
G
9
Posts: 298
Reputation: 5,367

Post » Tue Jun 06, 2017 8:06 pm

Rex's date plug gives you Unix timestamp.
All you have to do for elapsed time is save the timestamp to local storage, and subtract the saved value from the current timestamp when the user plays again.
Image ImageImage
B
168
S
50
G
169
Posts: 8,282
Reputation: 108,193

Post » Tue Jun 06, 2017 8:17 pm

I used the timeAwayL plugin but can not find any help on how to use the plugin. However, if you know a guide on how to do this I would really be useful
B
14
S
7
Posts: 17
Reputation: 1,238

Post » Tue Jun 06, 2017 9:18 pm

An example using the date plug:
https://www.dropbox.com/s/zprnm3t43hu7e ... .capx?dl=0
Click the button to start a timer.
Refresh the browser to see the elapsed time.

I think it works approximately the same as the time away plug does. It just sets the storage less than his example

Fun fact:
Unix time is about as old as me.
I'd ask Mom to be sure, but, eww.
Happy newt year!

Edit:
Here's the plug: http://c2rexplugins.weebly.com/rex_date.html
Image ImageImage
B
168
S
50
G
169
Posts: 8,282
Reputation: 108,193

Post » Tue Jun 06, 2017 9:37 pm

But is it possible to make a countdown?
B
14
S
7
Posts: 17
Reputation: 1,238

Post » Tue Jun 06, 2017 9:46 pm

Can you do such a thing to do the countdown?

{ system.every tick : set text to floor floor(Timer/60 %60) & ":" & floor(Timer%60)
system.Timer > 0: system subbtract dt from Timer
system.Timer < 0: system set Timer to 0
}

Can you do a similar thing? Even with the timeAwayL plugin or the date plugin? And also be able to give a precise time for example as I said before making a countdown from 15:00 minutes to 0. And when it reaches 0 the timer locks
B
14
S
7
Posts: 17
Reputation: 1,238

Post » Tue Jun 06, 2017 10:24 pm

I think a 15 minute countdown would be:
(15*60)-((unixtimestamp-mytimer)*0.001)

Here's a nice plug for time formatting to keep you from getting floored to death:
plugin-tr-clockparser_t191667
Image ImageImage
B
168
S
50
G
169
Posts: 8,282
Reputation: 108,193

Next

Return to How do I....?

Who is online

Users browsing this forum: guannstar, marcinkowski, Yahoo [Bot] and 19 guests