SetInterval - Forum

Forum Navigation
You need to log in to create posts and topics.

SetInterval

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

 

 

 

 

 

 

 

@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" ""

 

@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.

Muchas 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