How do I work with timers?

Get help using Construct 2

Post » Tue Mar 04, 2014 11:06 pm

Hello,

I have a problem with the timers option in Construct 2. I wanted to create a timer in my project. Let's say when a player presses a button the timer goes on. It stays like that forever, or at least until the player presses the button that restarts it. This means that even when the game is off the timer will keep going. Given these conditions, the timer would need to consist of days, minutes and seconds.

Now I've created a text object and I gave it a timer behaviour. I played with it for a while but to no luck. I am not really sure what expressions I should use and in what way I could create this kind of a scenario. To add to the confusion, aside from the timer behaviour there is a "timer" expression.

So yeah, really struggling here.

Any help?
B
9
S
1
Posts: 51
Reputation: 644

Post » Tue Mar 04, 2014 11:35 pm

if you want it to keep counting while you are out of the app you need to consider the system day and time instead.

Save it when he clicks and then compare it to what it is when the users clicks again.

Rexrainbow made a nice plugin for date and time you can use.
https://www.scirra.com/forum/viewtopic.php?t=63492&start=0
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Wed Mar 05, 2014 12:47 am

So you are suggesting that I should create a global variable that will save the time once the user leaves the app and then compare the time the user entered the app again with the saved time?

I think I can make that happen.

I am not sure how to set the timer yet, I guess I need to play with the plug-in a bit
B
9
S
1
Posts: 51
Reputation: 644

Post » Wed Mar 05, 2014 7:23 am

Yes that is what I am suggesting. You can use webstorage to persist the value between game sessions.
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Wed Mar 05, 2014 11:41 am

Yeah, good idea. I think I will be able to do that.

The problem I have now is I don't know how to set the timer. Every time I start it it's just stuck at 0 or 1. Like, the commands for the timer are so confusing that it's driving me crazy.
B
9
S
1
Posts: 51
Reputation: 644

Post » Wed Mar 05, 2014 1:15 pm

I am currently not home. But you can have a look at the .capx linked in this topic.

https://www.scirra.com/forum/viewtopic.php?f=147&t=88746&p=702329&hilit=calendar#p702329

I know it uses the date plugin.

Let me know if that does not help you, then I can throw something together sometime this evening.
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Wed Mar 05, 2014 8:32 pm

cvp wrote:I am currently not home. But you can have a look at the .capx linked in this topic.

https://www.scirra.com/forum/viewtopic.php?f=147&t=88746&p=702329&hilit=calendar#p702329

I know it uses the date plugin.

Let me know if that does not help you, then I can throw something together sometime this evening.


I looked at the example you sent me. It seemed pretty complicated at first but once analyzed further it didn't seem that bad. My concern is the actual usability of the .capx given that the example only shows today's date (unless I did something wrong). I don't think I would be needing that in my app, instead, I simply want to show the time since the button has pressed (for example) and count it until the player presses another button. That time might be 20 days 35 hours, 23 mins and 13 seconds or may just be 10 minutes. No rules to that.

Sorry if I am bothering you too much, it's not that I am a complete noob to construct, but this thing is really making huge problems for me, and given that it is a key to the app I am building, I am really looking into any options for solving it.

thank you once again!
B
9
S
1
Posts: 51
Reputation: 644

Post » Wed Mar 05, 2014 8:49 pm

Try this: https://dl.dropboxusercontent.com/u/2560922/mobiledev/forum/saveTimestamp.capx

It gets the unix timestamp (time since Jan 01 1970) in milliseconds and stores it in webstorage.
Second click (and the once after) will update the difference in time since the first click.

Hope that clears it up a bit for you.

And p.s. you cannot bother me. I know how it is to be stuck on something. I just hope I can supply some help.
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Wed Mar 05, 2014 10:30 pm

Ok, so I found a much easier way to do it.

I created 4 global variables.

-seconds
-minutes
-hours
-days

I then created an event for each and every one of them. Every 1 second add 1 to seconds. Sub-event, compare "seconds" = 60 then set value to 1. Every 60 seconds my "seconds" timer resets to 1. At this point I am figuring out how to compare the "minutes" variable with the "seconds" variable. So when "seconds" reaches 60 I add 1 to the "minutes"

Repeat the process for hours and day of course.

I feel I am so close!
B
9
S
1
Posts: 51
Reputation: 644

Post » Wed Mar 05, 2014 11:03 pm

I am a bit confused.... have you looked at the example I posted? you will get the interval between the two clicks in milliseconds.

then just convert the milliseconds to whatever you want: days, hours, minutes, seconds etc.
I do not see a reason why you would do all the events...
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests