Adding Time to a Timer when Player Collects Target

Would appreciate help with a student’s issue with timer and adding time to the timer as a result of collecting a sprite in the game. Thank you so much!

Link to the project or level:[Game Lab -]

What I expect to happen:

Player collects a star and the timer increases by 20 seconds.

What actually happens:

Nothing, no change in timer

What I’ve tried:

var timer = 100 - world.seconds;


timer = timer +20;

star.x = 1000;


Created a new variable

var time2 = 100;

var time = time2 - world.seconds;


time2 = 120;

star.x =1000;


Hi @sheri.mcnair,

What a great game!
You were on the right track by using the time2 variable. The variable just needs to be used to set the initial time so when it is updated when the player touches the star, the timer is also updated.

So, on line 43, update time2 = 60. Then, on line 296, make sure to use the time2 variable in the timer: time = time2 - World.seconds;
Finally, on line 76, when the player is touching the star, time2=130.

Good Luck!

Hi Michelle,
Ah-ha moment!
Thank you so much (again) for taking the time to look at this and coming up with a solution!

1 Like