Problem whit for loop
2Fast
Posts: 90
I'm trying to atualize every second on my TP screen a timer ... and I'm trying this:
The variable nTIME starts with number 60
But nothing happens ... so I checked on debugging and the nTIME just decrease once and the variable nATUALIZE didn't increase ... Please, where is dumb mistake?
Thank you!
DEFINE_FUNCTION fnTIMER() { FOR(nATUALIZE = 1; nATUALIZE <= 60; nATUALIZE++) { IF(!bRUNNING) { ON[bRUNNING] nTIME = nTIME-1 SEND_COMMAND dvTP,"'^TXT-33,0,',ITOA(nTIME)" WAIT 10 { OFF[bRUNNING] } } } }
The variable nTIME starts with number 60
But nothing happens ... so I checked on debugging and the nTIME just decrease once and the variable nATUALIZE didn't increase ... Please, where is dumb mistake?
Thank you!
0
Comments
You would be better served by doing the whole thing in a timeline. Let fnTimer start up a repeating timeline that counts down from 60 to 0 once a second. Put your send_command to the panel in the timeline event, and have the timeline kill itself when it hits zero.
Thanks!
timeline_event[onesecondTimeline]
{
if (countdown>0)
{
countdown--
if (countdown) send_command TP,"'TXT1-',itoa(countdown)"
else send_command TP,'TXT1- ' //to clear the countdown
}
}
Set Countdown to what ever you want.
You could even pause and resume the timeline with the value of countdown. If CountDown = 0 pause the timeline.
This code has the advantage of ending the timeline when your countdown is over. You could then use the timeline again for 90 seconds, or 400 seconds, or whatever, just set nCountdown to whatevery ou want, and create the timeline.
And if you're going to use it a lot, just create this function
and then you just call start_countdown(60) or whatever.
I prefer killing the timeline when you're not using it to letting it run all the time, but there are many ways to do it and I just wanted to show another example.
J
Good to know! I didn't think to look for this.
I'll do this right now thanks again!