Forum Discussion
Bingo Counter JavaScript Bug
CatherineG
Try to optimize the script to provide real-time updates by running a short interval loop that keeps bingo_Count current. Also, using a simple for loop instead of .filter() avoids creating temporary arrays and performing unnecessary string operations, making it faster and more efficient. The count can then be easily accessed in a separate script via setVar("Bingo_Count", bingo_Count") when a button is clicked. This ensures the count remains accurate, even if buttons are clicked very quickly. Given the small number of variables, the interval has negligible impact on CPU load, so there’s no performance concern.
Example:
Run when the timeline starts:
const bingoVarNames = [
"B1_True","B2_True","B3_True","B4_True","B5_True",
"I1_True","I2_True","I3_True","I4_True","I5_True",
"N1_True","N2_True","N3_True","N4_True","N5_True",
"G1_True","G2_True","G3_True","G4_True","G5_True",
"O1_True","O2_True","O3_True","O4_True","O5_True"
];
setInterval(() => {
let count = 0;
for (let i = 0; i < bingoVarNames.length; i++) {
if (getVar(bingoVarNames[i])) count++;
}
window.bingo_Count = count;
}, 200);
Run when the user clicks a button
setVar("Bingo_Count", window.bingo_Count);
This entire process could be handled in a single JavaScript script to manage rectangle states without the need for additional triggers. Let me know if you’d like me to assist with that.