0
Answered
Cyclic repetition of functions
Alexey Grishanin 10 years ago
in iRidium Script / Interface scripts
•
updated by Oksana (expert) 10 years ago •
2
Hello,
Please explain why in the following script:
function byte1(val)
{
return val >>> 24
};
function ReadEvent(val)
{
IR.Log("byte value 1: "+ byte1(val));
};
function WriteLog ()
{
IR.Log("message")
};
IR.AddListener(IR.EVENT_START,0,function()
{
IR.SetInterval(5000,WriteLog);
IR.SetInterval(5000,ReadEvent(1830317336));
});
the ReadEvent function does not work in cycles (every 5 seconds)? WriteLog works in cycles, the code is executed each 5 seconds.
Please explain why in the following script:
function byte1(val)
{
return val >>> 24
};
function ReadEvent(val)
{
IR.Log("byte value 1: "+ byte1(val));
};
function WriteLog ()
{
IR.Log("message")
};
IR.AddListener(IR.EVENT_START,0,function()
{
IR.SetInterval(5000,WriteLog);
IR.SetInterval(5000,ReadEvent(1830317336));
});
the ReadEvent function does not work in cycles (every 5 seconds)? WriteLog works in cycles, the code is executed each 5 seconds.
Customer support service by UserEcho
The SetInterval method cannot take function activation as a parameter. Only a link to the function is sent to the method. Or, if you need to execute the function activation with a parameter, you need to wrap the activation inot the unnamed function. See the example:
IR.SetInterval(5000, function () {
ReadEvent(1830317336)
]);
or named:
function ReadEventCall(){
ReadEvent(1830317336)
}
IR.SetInterval(5000, ReadEventCall);
_______________________________________________________________________________________________________
Добрый день, Алексей!
Метод SetInterval не может принимать вызов функции как параметр. В метод передается только ссылка на функцию или же если требуется выполнить вызов функции с параметром, то надо обернуть вызов в не именованную функцию. См. пример:
IR.SetInterval(5000, function () {
ReadEvent(1830317336)
]);
или именованную:
function ReadEventCall(){
ReadEvent(1830317336)
}
IR.SetInterval(5000, ReadEventCall);