Timer run in background

0 favourites
  • 13 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • 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.

  • 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

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

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

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

  • 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

  • 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

  • But is it possible to make a countdown?

  • 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

  • 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:

  • Hey but so you can do this thing ie create a countdown similar to clash of clans? But without using a server. I would like to do for example that I touch a button and I get a write with a countdown for example 15:00 minutes and if I close the application for 10:00 minutes and return it to me it appears that 5:00 minutes remain to complete this action I do not know If I explain it ..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes. What I've shown is probably the simplest method. You would just need to save the length of the original countdown(15 minutes) to local storage.

    Other methods might include the timer behavior using the save slot feature.

  • I wrote this way (My Timer background) and it works only when I leave the app but when it does not resume within the timer .. and when it reaches 0 continues and goes below 0. How can I make it appear that is written in this way? 15: 00 instead of 900.00? And that when the timer gets zero it stops and can you connect the classic timer with the backgroun timer?

    --- Classic timer ---

    {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

    }

    --- My Timer background ---

    {System: on start layout: local storage: check item "mytimer exist;

    LocalStorage: on item "mytimer" exist: localStorage: get item "mytimer";

    LocalStorage: on item "mytimer" get: text: set text to (15 * 60) - ((Date.UnixTimestamp-LocalStorage.ItemValue) * 0.001);

    Button: on clicked: LocalStorage: Set item: Setitem "mytimer" to Date.UnixTimestamp;

    LocalStorage: On item "mytimer" set: text: Set text to "Timer set".

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