Using Variables in Wait Blocks... any good way to do it?
GasHed
Posts: 31
If I have the following code:
Thanks,
Pat
DEFINE_CALL 'POPUP_CONTROL' (INTEGER TP) { SEND_COMMAND dvTPALL[TP],"'@PPN-PopUp;MainPage'" } . . . DEFINE_EVENT[dvTPALL,btnPOPUP] { PUSH: { LOCAL_VAR INTEGER I FOR(I=1;I<10;I++) { WAIT 10 { CALL 'POPUP_CONTROL' (I) } } } }It will not execute for I=1 because once the wait executes, the loop for I will be at a different increment, and probably to I=11 already. This kinda stinks, because I might have a routine that shuts down a single zone, and I might want to shut down all the zones using a loop, but I can't do it with variables. Is there some trick to prevent this race condition with waits that I'm missing?
Thanks,
Pat
0
Comments
On general principle, I never create CALLs that are a single line long - you have to type a single line in to call it, why not just put that one line of code there? There are cases where it might be easier to update if separated out that way.
Now, if you just simplified that CALL to post it, that's another story. In that case, I would make the actual DEV for the panel the argument for your CALL, and inside the WAIT do this: CALL 'POPUP_CONTROL' (dvTPALL). The value of I is resolved into an individual device before the CALL is made, so by the time the value of I changes, the CALL already took place.
Thanks much for the input!
Pat
Jeff
Pat
BTW, you are aware that all your waits will execute at approximately the same time? Use this to prevent that from happening:
At the end of the call do:
Note this only works if the call can complete execution in less than it takes for the next wait to begin (in the example above .5 seconds)
Increment the global var at the end of the subroutine... really smart workaround
Pat