The Tutorials and Solutions category is only for posting your own code and demonstrations, not for requesting assistance. I’ve moved your post to a better category this time, please try remember for next time.
@Tougharms here is my first approach, these are my first experiences with timers, it seems to work.
I’m still testing. Any suggestions for improvement?
'use strict';
{
const runtime = require('@runtime'); //we need this to import Datatypes like PercentType
var myTimer; //it works with "var" andit doesn't work with "let", must be something about hoisting
function evaluate()
{
console.warn("Counted: " + cache.private.get("CachedCounter"));
cache.private.put("CachedCounter", 0);
myTimer = null;
}
console.warn("Start Timer Test Script");
let MyCounter = cache.private.get("CachedCounter");
if( MyCounter == null) //if counter doesn't exists, create cached counter
{
MyCounter = {times: 0};
cache.private.put("CachedCounter", MyCounter);
}
console.warn("Timer Info " + myTimer);
if(myTimer == null) // no timer started, so startup timer
{
cache.private.put("CachedCounter", 1);
myTimer = setTimeout(evaluate, 10000);
console.warn("Timer started");
}
else
{
const NewCounterValue = cache.private.get("CachedCounter") + 1;
cache.private.put("CachedCounter", NewCounterValue);
console.warn("new Counter value: " + NewCounterValue);
}
console.warn("Finished Timer Test Script");
}
'use strict';
{
const timeout = 10000;
const runtime = require('@runtime'); //we need this to import Datatypes like PercentType
var myTimer; //it works with "var" andit doesn't work with "let", must be something about hoisting
var myCounter; //it works with "var" andit doesn't work with "let", must be something about hoisting
function evaluate()
{
console.warn("Counted: " + myCounter + " within a time period of " + timeout + "ms");
myCounter = 0; //reset the counter
clearTimeout(myTimer);
myTimer = null;
}
console.warn("Start Timer Test Script");
console.warn("Timer id: " + myTimer);
if(myTimer == null) // no timer started, so startup timer
{
myCounter = 0;
myTimer = setTimeout(evaluate, timeout);
console.warn("Timer started");
}
else
{
myCounter = myCounter + 1;
console.warn("new Counter value: " + myCounter);
//here I can catch the "tripple Click immidiatly"
}
console.warn("Finished Timer Test Script");
}