Javascript delay

28 views
Skip to first unread message

christi...@gmail.com

unread,
Feb 24, 2022, 10:07:47 AM2/24/22
to CommandFusion Software
Hi all,

We need to activate a group of relays.  We can not use Macros as it is a dynamic group of relays (each relay can belong to a different group depending on the circunstances).  

The code is something like this:

for (indice_botones = 0; indice_botones < Lineas_Megafonia.Z2.length; indice_botones++) {
                                                                CF.runCommand("LANBridge", Lineas_Megafonia.Z2[indice_botones].rele_fisico;
                                                        }

But it seems like it works too quick and not all the relays respond.

On the other hand, we tried with:

for (indice_botones = 0; indice_botones < Lineas_Megafonia.Z2.length; indice_botones++) {
                                                                setTimeout(function () { CF.runCommand("LANBridge", Lineas_Megafonia.Z2[indice_botones].rele_fisico + " ON"); }, 100);
                                                        }

with a worse result.

Any ideas?

Regards!

Jarrod Bell

unread,
Feb 25, 2022, 6:56:14 PM2/25/22
to comman...@googlegroups.com, christi...@gmail.com
The variable "indice_botones" is being updated in the loop, so by the time the setTimeout runs, the same value will be used for all your runCommand calls since indice_botones is at its final value when the timeout runs.

So you need to send the indice_botones variable as a parameter to your setTimeout call like this:

setTimeout(function (x) {
    CF.runCommand("LANBridge", Lineas_Megafonia.Z2[x].rele_fisico + " ON");
}, 100, indice_botones);


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com

--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/commandfusion/5ec0b82d-bd36-4395-902d-18b72ca845a2n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages