Count down


#1

Hello
How can I make a countdown? Is there any examples available?
Thank you
Milenne


#2

Hi,
Here it’s an example:

var timer = 10; // for a 10 sec timer

parent.on("pointerdown", (e) => {Z.every(1000,myTimer); }); // call myTimer() every sec

function myTimer(){
    symbol.nodes.textField.text("timer: "+timer); // display the countdown in a text node
    if(timer--<=0)Z.everyOff(myTimer);  // cancel the call if timer <= 0 
}

Hope it can help. :slight_smile:


#3

Thank you jvouillon. That is what I am looking for. :wink:
What assets do I need to to have in place so I can add this code? Just a text image with nothing in it?
Thanks again.
Regards
Milenne


#4

You need just 2 things:

  • a plan (or an image) to set the script on the pointerDown() event
  • a text object to display the timer

Here it’s the zpp example: test.zpp (72.9 KB)


Timer functions
#5

Wonderful. I thought it would be much more difficult. Thank you so much!
:wink:
Milenne