on textChanged by computer change

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

on textChanged by computer change

Post by gilar » Sat Jan 09, 2016 10:00 am

Hello every body

I have a question about "on textChanged" handler

let say i have
-field1= field timer coundown
-button1= button for start and stop timer
-button2= button for play sound effect1
-button3= button for play sound effect2

I create code on field1 like this
on textChanged
if the field1 is "05:00" then
send "mouseUp" to button "button2"
end if
end textChanged


When countdonwn is running then the value change 05:00 nothing change anything.
What i expect is when timer value 05:00 the sound effect1 is playing

but if I type it manually 05:00 on field1 then the sound effect is playing

anyone cant give me guidance to a right direction

Commend and help will be appreciate

Thank You
Gilar | from INDONESIA

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: on textChanged by computer change

Post by Klaus » Sat Jan 09, 2016 11:58 am

Hi gilar,

1. very bad syntax and I wonder why (if) this has compiled:
...
if the field1 is "05:00" then
...
a. Do not use THE when accessing objects in Livecode - if field "field1"...
b. Use the object descriptor -> field "field1"
c. get used to put quotes around strings, and object names are strings -> field "field1"
d. VERY good advice: use meaningful names for your objects, "field1" or "button2" are NOT! 8)

2. Obviously the "textchanged" message is NOT triggered when the text is changed via script, which is the case here,
only when the user types something.

So you should modify the "countdown" script, which writes the time into your field "field1", to do what you want.
Please post the script if you need some help here.


Best

Klaus

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: on textChanged by computer change

Post by gilar » Sat Jan 09, 2016 1:46 pm

Klaus wrote:Hi gilar,

1. very bad syntax and I wonder why (if) this has compiled:
...
if the field1 is "05:00" then
...
a. Do not use THE when accessing objects in Livecode - if field "field1"...
b. Use the object descriptor -> field "field1"
c. get used to put quotes around strings, and object names are strings -> field "field1"
d. VERY good advice: use meaningful names for your objects, "field1" or "button2" are NOT! 8)
Yes ... you are right Klaus, Thank You
Now I change the name of text field and button
- timer_fld = field for timer
- timer_btn = button for Start and Stop Timer
- Sound_btn = button for sound Effect

Klaus wrote: 2. Obviously the "textchanged" message is NOT triggered when the text is changed via script, which is the case here,
only when the user types something.

So you should modify the "countdown" script, which writes the time into your field "field1", to do what you want.
Please post the script if you need some help here.


Best

Klaus
Now I use count up Timer, but the principe is same.
I want to trigger sound effect when timer value 05:00

This is my Count Up Script

Code: Select all

global holdTime
on mouseUp      
   if the backgroundcolor of me is 46, 56, 63 and the ticks  - holdTime >30 then  --NEW
      set the backgroundcolor of me to 115, 153, 100
      put the ticks into holdTime -- NEW
      DoCountUp
   else
      set the backgroundcolor of me to 46, 56, 63
      cancel item 1 of last line of the pendingMessages
   end if
end mouseUp

on DoCountUp
   if the backgroundcolor of me is 115, 153, 100 then
      set the numberformat to 00
      put format("%02d:%02d",pTime[4],pTime[5],pTime[6]) into tNewTime
      add 1 to char 4 to 5  of word 1 of field timer_fld of card 001
      if  char 4 to 5 of word 1 of field timer_fld of card 001 = 60 then
         add 1 to char 1 to 2 of word 1 of field timer_fld of card 001
         put 00 into char 4 to 5 of word 1 of field timer_fld of card 001
         //Script for CasparCG
         put "CG 1-9 UPDATE 1 " into tm1xml
         put quote after tm1xml
         put "<templateData><componentData id=\" after tm1xml
         put quote after tm1xml
         put "timer1\" 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 of card 001  after tm1xml
         put "\" after tm1xml
         put quote after tm1xml
         put " /></componentData></templateData>" after tm1xml
         put quote after tm1xml
         put field ipport of card 001 after server 
         write tm1xml  & format("\r\n") to socket server
      else
          //Script for CasparCG
         put "CG 1-9 UPDATE 1 " into tm1xml
         put quote after tm1xml
         put "<templateData><componentData id=\" after tm1xml
         put quote after tm1xml
         put "timer1\" 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 of card 001 after tm1xml
         put "\" after tm1xml
         put quote after tm1xml
         put " /></componentData></templateData>" after tm1xml
         put quote after tm1xml
         put field ipport of card 001 after server
         write tm1xml  & format("\r\n") to socket server
      end if
      send "DoCountUp tNewTime" to me in 1 second
   end if
end DoCountUp
where I have to put command trigger for sound effect?
Any Comment and Help wouldbe appreciate

Best


Gilar Kadarsah | from INDONESIA
Gilar | from INDONESIA

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: on textChanged by computer change

Post by Klaus » Sat Jan 09, 2016 1:58 pm

Selamat siang Gilar,

where is pTime[4] etc. coming from resp. what is in the array?
Looks to me that you can simply:
put tNewTime into fld "timer_fld"
?
But maybe not :D
...
put format("%02d:%02d",pTime[4],pTime[5],pTime[6]) into tNewTime
## add 1 to char 4 to 5 of word 1 of field timer_fld of card 001
## QUOTES! 8)
add 1 to char 4 to 5 of word 1 of field "timer_fld" of card 001
...

And no need to format the card number:
... of cd 1
Is enough.

But maybe you can check right here:

Code: Select all

...
 put format("%02d:%02d",pTime[4],pTime[5],pTime[6]) into tNewTime
if tNewTime = "05:00" then
  ## do your sound thing here...
end if
...
Best

Klaus | from germany

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: on textChanged by computer change

Post by gilar » Sat Jan 09, 2016 3:43 pm

Klaus wrote:Selamat siang Gilar,

where is pTime[4] etc. coming from resp. what is in the array?
Looks to me that you can simply:
put tNewTime into fld "timer_fld"
?
But maybe not :D
...
put format("%02d:%02d",pTime[4],pTime[5],pTime[6]) into tNewTime
## add 1 to char 4 to 5 of word 1 of field timer_fld of card 001
## QUOTES! 8)
add 1 to char 4 to 5 of word 1 of field "timer_fld" of card 001
...
Selamat Malam Kaluse, Terimakasih Banyak
Sekarang di Indonesia sudah malam Hari .... :)

Actually I'm new in programming, and new in Livecode so I'm completly beginer.
I Really don't understand how the timer code work All.
I Just copas and edit that code frome GithHub.
But I'm learning. I use Livecode to create Application wich connect to CasparCG

I put the code as you said in timer script. just like this:

Code: Select all

global holdTime
on mouseUp      
   if the backgroundcolor of me is 46, 56, 63 and the ticks  - holdTime >30 then  --NEW
      set the backgroundcolor of me to 115, 153, 100
      put the ticks into holdTime -- NEW
      DoCountUp
   else
      set the backgroundcolor of me to 46, 56, 63
      cancel item 1 of last line of the pendingMessages
   end if
end mouseUp

on DoCountUp
   if the backgroundcolor of me is 115, 153, 100 then
      set the numberformat to 00
      put format("%02d:%02d",pTime[4],pTime[5],pTime[6]) into tNewTime
      add 1 to char 4 to 5  of word 1 of field timer_fld of card 001
      if  char 4 to 5 of word 1 of field timer_fld of card 001 = 60 then
         add 1 to char 1 to 2 of word 1 of field timer_fld of card 001
         put 00 into char 4 to 5 of word 1 of field timer_fld of card 001
         //Script for CasparCG
         put "CG 1-9 UPDATE 1 " into tm1xml
         put quote after tm1xml
         put "<templateData><componentData id=\" after tm1xml
         put quote after tm1xml
         put "timer1\" 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 of card 001  after tm1xml
         put "\" after tm1xml
         put quote after tm1xml
         put " /></componentData></templateData>" after tm1xml
         put quote after tm1xml
         put field ipport of card 001 after server 
         write tm1xml  & format("\r\n") to socket server
      else
         //Script for CasparCG
         put "CG 1-9 UPDATE 1 " into tm1xml
         put quote after tm1xml
         put "<templateData><componentData id=\" after tm1xml
         put quote after tm1xml
         put "timer1\" 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 of card 001 after tm1xml
         put "\" after tm1xml
         put quote after tm1xml
         put " /></componentData></templateData>" after tm1xml
         put quote after tm1xml
         put field ipport of card 001 after server
         write tm1xml  & format("\r\n") to socket server
      end if
      send "DoCountUp tNewTime" to me in 1 second
   end if
   ================================================ NEW CODE
   if the field timer_fld is "05:00" then
      send "mouseUp" to button "Sound_btn"
   end if
   ================================================ NEW CODE
end DoCountUp


AND WORK LIKE CHARM .... thank you Klause ....
TERIMAKASIH BANYAK

Now i'm find out "pTime[4] etc." what is it mean?
Gilar | from INDONESIA

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: on textChanged by computer change

Post by Klaus » Sat Jan 09, 2016 4:32 pm

Hi gilar,
gilar wrote:Selamat Malam Kaluse, Terimakasih Banyak
Sekarang di Indonesia sudah malam Hari .... :)
I actually cheated and looked up "Good day" in malayan via Google,
so no idea what you are writing here :D
gilar wrote:Actually I'm new in programming, and new in Livecode so I'm completly beginer.
I Really don't understand how the timer code work All.
I Just copas and edit that code frome GithHub.
But I'm learning. I use Livecode to create Application wich connect to CasparCG
The code is quite complicated to be honest and I have also problems to understand it.

I can recommend some great learning resources to get the basics of Livecode, check this page:
http://www.hyperactivesw.com/revscriptc ... ences.html
gilar wrote:...
if the field timer_fld ...
...
Well, we already talked about this, right? 8)
gilar wrote:... thank you Klause ....
It is Klaus without an E!
gilar wrote:Now i'm find out "pTime[4] etc." what is it mean?
I have asked you first! :D
The ARRAY pTime is not declared in your script, neither LOCAL nor GLOBAL!
So I still wonder why the script works! :shock:


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: on textChanged by computer change

Post by jacque » Sun Jan 10, 2016 6:21 pm

If the array is undeclared then the values will be empty. The format function will still return the short time values so the rest of the handler still works. I suspect the array may have held the values for the internet date or maybe the long time,where there would be more keys.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply