How do I make a timer

Discussion and feedback on Construct 2

Post » Sat Aug 06, 2011 7:53 am

Hello,

Sorry everyone, but I am a complete novice. Can anyone tell me how to make a timer that ends the game once it runs out? I've been on here for hours, and can't seem to find any documentation on this.

Thanks in advance

Dave
B
6
S
1
G
1
Posts: 52
Reputation: 829

Post » Sat Aug 06, 2011 8:28 am

Create an event at start of layout create a variable and give it an initial value like 10, then use an every event to subtract 1 from the variable.

Create a new event that says if variable is equal to or lower than 0 end game.Ethan2011-08-06 08:28:57
B
37
S
19
G
18
Posts: 613
Reputation: 10,231

Post » Sat Aug 06, 2011 12:48 pm

An even easier way is System - compare time - equal to 60 seconds (or whatever your limit), then add an action to end the game (go to another layout or something similar).
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Sat Aug 06, 2011 6:48 pm

Hi Thanks for the replies,

I do not see an action that says end the game
B
6
S
1
G
1
Posts: 52
Reputation: 829

Post » Sat Aug 06, 2011 7:39 pm

All squared away thanks!!
B
6
S
1
G
1
Posts: 52
Reputation: 829

Post » Sun Oct 23, 2011 6:18 am

Is there a way to start a timer mid game, and have it do an action when the time is met?

Or - for an object after it spawns, have it destroy itself after x ticks?

B
31
S
10
G
7
Posts: 30
Reputation: 5,408

Post » Sun Oct 23, 2011 6:26 am

Never mind. Got it. :-)

Gave the object a number instance variable.
Each tick, I subtract one.
Event - if it's less than or equal to 0, I destroy it.

Thanks.
B
31
S
10
G
7
Posts: 30
Reputation: 5,408

Post » Sun Oct 23, 2011 6:27 am

So - for a mid game timer - create a timer object with an instance variable of X. On System tick - subtract one. Event - when 0, launch your actions.
B
31
S
10
G
7
Posts: 30
Reputation: 5,408

Post » Sun Oct 23, 2011 3:18 pm

[QUOTE=StonePaleAle]On System tick - subtract one.[/QUOTE]
If you do that, your timer changes speed depending on the framerate, which is probably unfair. If you subtract dt instead of one then the variable will count down one every second regardless of the framerate. Have a read of the Delta-time and framerate independence tutorial.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Tue Nov 15, 2011 3:24 am

Thanks for the info!
B
31
S
10
G
7
Posts: 30
Reputation: 5,408

Next

Return to Construct 2 General

Who is online

Users browsing this forum: KaMiZoTo and 20 guests