Page 1 of 1

UPDATE TIMER ONTHE FLY

Posted: Tue Oct 20, 2015 8:54 am
by gilar
Hi ... Sorry for nubie question ...
I have a countdown timer on field "TIMER_fld" the format is 00:00 (minute:secon)
it will start/pause with button "Start"
and i want update the timer with button option menu "SECON_update"

here are the code:
"TIMER_field"

Code: Select all

on textchanged

end textchanged
button "Start"

Code: Select all

on mouseUp
   If the label of ME is "Start" then
      set the label of ME to "Stop"
      set the backgroundcolor of ME to green
else 
   set the label ME to "Start"
   set the backgroundcolor of ME to empty
end if
   DoCountDown field TIMER_fld
end mouseUp

on DoCountDown pTime
   if label of button "Start" is "Start"
else
   convert pTime to seconds 
   subtract 1 from pTime 
   convert pTime to dateItems 
   split pTime by "," 
   put format("%02d:%02d",pTime[4],pTime[5],pTime[6]) into tNewTime 
   put tNewTime into fld "TIMER_fld" 
   //CASPAR
   put "CG 1-2 UPDATE 1 " into tm1xml
   put quote after tm1xml
   put "<templateData><componentData id=\" after tm1xml
   put quote after tm1xml
   put "f3\" after tm1xml
   put quote after tm1xml
   put "><data id=\" after tm1xml
   put quote after tm1xml
   put "text\" after tm1xml
   put quote after tm1xml
   put " value=\" after tm1xml
   put quote after tm1xml
   put tNewTime after tm1xml
   put "\" after tm1xml
   put quote after tm1xml
   put " /></componentData></templateData>" after tm1xml
   put quote after tm1xml
   put field ipport1 of card 003 after server1
   write tm1xml  & format("\r\n") to socket server1
   if tNewTime = "00:00" then do TimesUp
   else
      send "DoCountDown tNewTime" to me in 1 second
   end if
end if
end DoCountDown 

on TimesUp 
   
   put "CG 1-2 UPDATE 1 " into tm1xml
   put quote after tm1xml
   put "<templateData><componentData id=\" after tm1xml
   put quote after tm1xml
   put "f3\" after tm1xml
   put quote after tm1xml
   put "><data id=\" after tm1xml
   put quote after tm1xml
   put "text\" after tm1xml
   put quote after tm1xml
   put " value=\" after tm1xml
   put quote after tm1xml
   put field TIMER_fld after tm1xml
   put "\" after tm1xml
   put quote after tm1xml
   put " /></componentData></templateData>" after tm1xml
   put quote after tm1xml
   put field ipport1 of card 003 after server
   write tm1xml  & format("\r\n") to socket server
end TimesUp

on TimesStopped

end TimesStopped

option menu "SECON_update"

Code: Select all

on mouseUp
   put the label name of me into char 4 to 5 of word 1 of line 1 of field "TIMER_fld"
end mouseUp
-The timer is running
-Stop and start button also running
-Update button Work when timer pause
-But It Won't work UPDATE when timer on

? What I want is ... I can UDATE Timer on the fly when the Timer countdown.

Anybody Know What wrong with my code?

Any comment and help Would be Apriciate ...

Thanx

Re: UPDATE TIMER ONTHE FLY

Posted: Wed Oct 21, 2015 1:20 am
by dunbarx
Hi.

If you want to use an option menu the way you have it set up, in its script, change the handler "mouseUp" to "mouseDown".

Write back with your thoughts...

Craig Newman

Re: UPDATE TIMER ONTHE FLY

Posted: Thu Oct 29, 2015 4:13 am
by gilar
dunbarx wrote:Hi.

If you want to use an option menu the way you have it set up, in its script, change the handler "mouseUp" to "mouseDown".

Write back with your thoughts...

Craig Newman
Thanx Craig for comment, I try this code but no Luck:

Code: Select all

on mouseDown
   put the label name of me into char 4 to 5 of word 1 of line 1 of field "TIMER_fld"
end mouseDown

Re: UPDATE TIMER ONTHE FLY

Posted: Thu Oct 29, 2015 2:19 pm
by dunbarx
Oh. Now i see what you want.

In the pop-up script, place this:

Code: Select all

on menuPick pItemName
       put pItemName into char 4 to 5 of word 1 of line 1 of field "TIMER_fld"
end menuPick
Now the field will be loaded with the value you choose from the pop-up. I assume this is a valid string for the ongoing process not to choke on. It would be more robust if you set the itemDel to ":" and loaded item 2. But that is for later.

But when you do this, check out your "doCountDown" code. The variable "tNewTime" will overWrite your hand loaded value each pass through the handler. Try it. You need to change your methodology so that variable is supplanted.

Craig

Re: UPDATE TIMER ONTHE FLY

Posted: Thu Oct 29, 2015 3:56 pm
by dunbarx
Just an aside.

Using the "format" function with an array is fine, since it works :D :

Code: Select all

  convert pTime to seconds 
   subtract 1 from pTime 
   convert pTime to dateItems 
   split pTime by "," 
   put format("%02d:%02d",pTime[4],pTime[5],pTime[6]) into tNewTime 
but I would have just

Code: Select all

  convert pTime to dateItems 
   put item 5 of pTime & ":" & item 6 of pTime -1 into tNewTime 
Just think this is simpler and more adorable.

Just another note. The incantation order you made for the "format" function, and the array you made, use the hours and minute portions of the dateItems. Did you mean:

Code: Select all

 put format("%02d:%02d",pTime[5],pTime[6]) into tNewTime 
Two incantations will ignore the third item in your array element list.