Timer

For questions about using Classic.

Post » Sat Dec 06, 2008 8:28 pm

How do you do a basic timer in construct?
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Sat Dec 06, 2008 8:32 pm

What are you timing?
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Dec 06, 2008 10:01 pm

No just a timer like countdown, actually, count up timer...
Also, it should be activated and not run in 'Always'
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Sun Dec 07, 2008 1:54 am

Okay then. Here's how I did the timers in This Cursed Rock (I had a lot of cutscene events that were dependent on time).

Create a variable called "timerCount" either as a global or in one of your objects. Next, create a variable called "timerStart." Set both to default at 0.

Next, when you want your timer to start, set "timerStart" to 1. Then do this:

[code:1wjhlad9]
+Value('timerStart') equal to 1
+Every 1000 MS
->Add 1 to Value('timerCount')
[/code:1wjhlad9]

Then every second it will add 1 to timerCount. Actually, the way "Every x MS" works is it will add 1 to timerCount immediately when it starts, rather than waiting 1 second, so at the end of 1 second your timerCount will be 2, at the end of 2 seconds your timerCount will be 3, and so on, so it'll always be one number ahead of the actual number of seconds passed. If you need an exact count you can add an event that checks for another variable called "beginCounting" or something:

[code:1wjhlad9]
+Value('timerStart') equal to 1
+Every 1000 MS
+Value('beginCounting') less than 2
->Add 1 to Value('beginCounting')
+Value('beginCounting') greater than 1
->Add 1 to Value('timerCount')
[/code:1wjhlad9]

This is just how I did my timers though, I'm sure there are other, better ways to do it. And if this doesn't do what you need then I suggest you get a little more detailed with your question, it'll be easier to help you that way.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sun Dec 07, 2008 2:17 am

Thank you.. I tried the concept and it worked.
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Sun Dec 07, 2008 2:21 am

You can also use the Function object to call a function after X milliseconds.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests