
Quote from rrey on January 12, 2020, 9:44 pmHola,
Tengo un problema con SetInterval. Uso este código para un contador de segundos. El problema es que no se inicia desde 0, se inicia en 10. El código que uso es:
setVar [segundos] 0
SetInterval 1000 "contador" [segundos]Y la subrutina contador:
SetVar [segundos] [segundos]+1
Con la función Math tampoco funciona.
No sé si es un problema del programa o mío.
Roger Rey
Hola,
Tengo un problema con SetInterval. Uso este código para un contador de segundos. El problema es que no se inicia desde 0, se inicia en 10. El código que uso es:
setVar [segundos] 0
SetInterval 1000 "contador" [segundos]
Y la subrutina contador:
SetVar [segundos] [segundos]+1
Con la función Math tampoco funciona.
No sé si es un problema del programa o mío.
Roger Rey
Quote from Gaev on January 13, 2020, 5:12 am@rrey
The Help file for the SetInterval command is a bit unclear ... but the third parameter in ...
SetInterval milliseconds "subroutine" [interval var]... i.e. [interval var] is NOT A COUNTER but a place to hold the REFERENCE/ID (to be used later with the corresponding ClearInterval command) ... this way your App can have multiple Timers (each with its own Interval and Subroutine) going at the same time.
You have to maintain your counters in your own separate variables.
This works for me ...
SetVar [gknumber] 0 SetInterval 1000 "gkcounter" [gkseconds]... with the code for subroutine gkcounter ...
SetObjectHTML "VarDisplay" "[gknumber]" SetVar [gknumber] 1+[gknumber]... and the code to stop the timer ...
ClearInterval [gkseconds] SetObjectHTML "VarDisplay" ""
The Help file for the SetInterval command is a bit unclear ... but the third parameter in ...
SetInterval milliseconds "subroutine" [interval var]
... i.e. [interval var] is NOT A COUNTER but a place to hold the REFERENCE/ID (to be used later with the corresponding ClearInterval command) ... this way your App can have multiple Timers (each with its own Interval and Subroutine) going at the same time.
You have to maintain your counters in your own separate variables.
This works for me ...
SetVar [gknumber] 0 SetInterval 1000 "gkcounter" [gkseconds]
... with the code for subroutine gkcounter ...
SetObjectHTML "VarDisplay" "[gknumber]" SetVar [gknumber] 1+[gknumber]
... and the code to stop the timer ...
ClearInterval [gkseconds] SetObjectHTML "VarDisplay" ""

Quote from luishp on January 13, 2020, 9:27 am@rrey, @gaev está en lo cierto.
Normalmente el objeto Timer es suficiente para poner contadores de tiempo. SetInterval es para un uso más avanzado y para personas familiarizadas con JavaScript, ya que el funcionamiento es idéntico.
Saludos.
@rrey, @gaev está en lo cierto.
Normalmente el objeto Timer es suficiente para poner contadores de tiempo. SetInterval es para un uso más avanzado y para personas familiarizadas con JavaScript, ya que el funcionamiento es idéntico.
Saludos.

Quote from rrey on January 13, 2020, 8:52 pmMuchas gracias @luishp @Gaev.
Ya me funcionan las dos. Usaba el mismo nombre de variable en la función y en la variable que se autosuma.
Rpger Rey
Ya me funcionan las dos. Usaba el mismo nombre de variable en la función y en la variable que se autosuma.
Rpger Rey