# Variables and DT

Get help using Construct 2

### » Sat Sep 14, 2013 6:48 am

I'm trying to figure out how add to a Final Score variable so the duration is always the same regardless of the score.

ie. You beat the level and your score is 12,000, in 2 seconds your Final Score meter will go from 0 to 12,000 increasing by x.

Currently I'm just using "add 100" to Final Score every tick if Final Score variable =/ Score variable. and then when the final score is over it sets the text to the score variable. Obviously this isn't timed like I want it at all, and I'm having trouble figuring out where to start...

Any help would be greatly appreciated!

Thanks.
B
52
S
13
G
1
Posts: 580
Reputation: 4,639

### » Sat Sep 14, 2013 10:03 am

You could lerp it.

currentscore starts at 0.

lerp(currentscore,finalscore,10*dt)

Play around with the 10*dt which is the speed. I believe 60*dt is 1 second.
It will never quite reach the final score though as lerp slows down as it progresses.
You'd have to put it in a condition like,

currentscore<finalscore-1 do lerp

currentscore>=finalscore-1 set score to final score.Ethan2013-09-14 10:12:33
B
43
S
23
G
21
Posts: 735
Reputation: 12,142

### » Sat Sep 14, 2013 2:26 pm

[QUOTE=ome6a1717] I'm trying to figure out how add to a Final Score variable so the duration is always the same regardless of the score.

ie. You beat the level and your score is 12,000, in 2 seconds your Final Score meter will go from 0 to 12,000 increasing by x.

Currently I'm just using "add 100" to Final Score every tick if Final Score variable =/ Score variable. and then when the final score is over it sets the text to the score variable. Obviously this isn't timed like I want it at all, and I'm having trouble figuring out where to start...

Any help would be greatly appreciated!

Thanks.[/QUOTE] It's pretty easy.
Forget about all technical background information and just remember this:
When using dt ("delta time") on every tick, then everything you multiply with dt will result in the exact portion you need in this tick in order to reach the full result after one second.

You're aiming for two seconds, so you'd need half the score
6000 * dt => portion for this tick to reach 6000 after 1 second

Now just add it to a current score variable on every tick, and current score will be 12000 after two seconds.

on every tick -> add 6000*dt to current
current = 12000 -> do final score

If you want to be absolutely sure you can also use min():
on every tick -> set current to min(current + 6000 * dt, 12000)

this will prevent raising the score after reaching 12000

rule: number * dt = amount needed per tick to raise to number within a secondtulamide2013-09-14 14:29:29
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,289

### » Sat Sep 14, 2013 7:30 pm

@tulamide - brilliant! I think I FINALLY understand dt now!

Thanks to the both of you.
B
52
S
13
G
1
Posts: 580
Reputation: 4,639

Return to How do I....?

### Who is online

Users browsing this forum: fbarraza28, JoniArtha and 3 guests