Timer show remaining time

Hi! I am working on a game that you collect items in under 2 minutes. If time runs out it goes to a certain slide. If the person collects all items under 2 minutes, I would like the timer to stop and then show the remaining time on another slide. How do I do that? Thanks!

This is a bit more complex.
Again, I personally would work with JavaScript but it may be a bit easier to use native actions.
Time running out is a bit easier. If you are using the animated timer interaction and If that is all you need… just do a timer complete action.
image

In the case where all objects are found before time is up - I would stick to JavaScript for the control and build my own timer rather than using the animated timer via the GUI.
I don’t have time at the moment to work up the example but can perhaps later in the day.

Hopefully this helps get you started.

@Kimberly_Wymer
In this setup, I have JavaScript in three places.

  1. onLoad
  2. On a Begin Button
  3. On a click object

In the onLoad area I execute some JavaScript

// function for the countdown timer
// this function counts down, checks if all found by using totalScore
// and it checks if the timer has reached zero
window.countdown = function() {
    prez.variable("myTimer",prez.variable("myTimer")-1);
    
    if (prez.variable("totalPoints") >= 1000) {
        clearInterval(prez.variable("timer"));
        prez.showSlideAt(3);
    }

    if (prez.variable("myTimer") == 0) {
        clearInterval(prez.variable("timer"));
        prez.showSlideAt(2);
    }
}

Next we have the begin button.

// this code starts the timer and disables the button
// button is disabled because clicking it again would speed up countdown
prez.variable("timer",setInterval(countdown,1000));
prez.object("beginBtn").disable(true);

Finally we have the click object.

// Here we just add points for the object.
prez.variable("totalPoints",prez.variable("totalPoints")+100);

You might consider disabling or hiding all your objects at the start and use the begin button to re-enable or show them so that learners are not allowed to click on objects prior to the timer starting.

Hopefully this helps.

2 Likes

Hi @Kimberly_Wymer,

Your game logic appears to be similar to that of the “Defuse the Bomb” game: https://www.youtube.com/watch?v=gKlMrIRxwuA. You can refer to the project linked in the video description for more details.

I used the default events and actions along with JavaScript code to pause and hide the timer and audio.

Regards,

1 Like