triggering a handler at a specific time

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
keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

triggering a handler at a specific time

Post by keram » Wed Mar 19, 2014 11:34 am

Hi everybody,

In my stack I have 2 options: to either trigger a handler in the Next button at defined intervals (currently in seconds for testing purposes) or at a specific time.
Setting the the time intervals was easy although there may be some simpler or more correct way. But setting the specific time is not working.
I'm using this code:

Code: Select all

global gIncrement
on mouseUp
  set the twelveHourTime to false
   if the hilite of btn "Radio1" is "true" then
      --      put (label of btn "everyhours" * 3600 + label of btn "everyminutes" * 60) into gIncrement
      put (label of btn "everyhours" + label of btn "everyminutes") into gIncrement --used for development
      
      if timerIncrement is not in the pendingMessages then -- don't pile up timerIncrement
         send "timerIncrement" to me in gIncrement seconds
      end if
   else
      doItAtTime
   end if
end mouseUp

on timerIncrement
   send "timerIncrement" to me in gIncrement seconds
   send mouseUp to btn "next"
end timerIncrement

on doItAtTime
   if the short time =  (label of btn "onhour" &":"& label of btn "onminutes") then
      send mouseUp to btn "next" in 62 seconds
   end if
end doItAtTime
What do I have to correct to get the specific time setting working?
the stack is attached

keram
Attachments
DG-timing.zip
(16.87 KiB) Downloaded 186 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

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

Re: triggering a handler at a specific time

Post by Klaus » Wed Mar 19, 2014 2:02 pm

Hi keram,
keram wrote:But setting the specific time is not working.
what and where in the script is meant to "set the specific time"?


Best

Klaus

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: triggering a handler at a specific time

Post by keram » Wed Mar 19, 2014 2:42 pm

Hi Klaus,
Klaus wrote:what and where in the script is meant to "set the specific time"?
The script is in the "Save & Start"button and it is this:

....
else
doItAtTime
...

and

on doItAtTime
if the short time = (label of btn "onhour" &":"& label of btn "onminutes") then
send mouseUp to btn "next" in 62 seconds
end if
end doItAtTime

This is what I thought would work...

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

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

Re: triggering a handler at a specific time

Post by Klaus » Wed Mar 19, 2014 2:57 pm

Hi Keram,

aha! :D

I think that this condition will only apply ONCE a day, if at all:

Code: Select all

...
if the short time = (label of btn "onhour" &":"& label of btn "onminutes")
...
Is this really what/how you want to check?


Best

Klaus

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: triggering a handler at a specific time

Post by keram » Wed Mar 19, 2014 2:59 pm

Yes, just once a day.
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: triggering a handler at a specific time

Post by Mark » Wed Mar 19, 2014 4:48 pm

Hi,

The following handler executes a handler almost exactly on the time you want it to execute (it might be half a second off).

Code: Select all

// theHandler: name of the command to be executed (no functions)
// theTime: the time when to execute the command
// assuming that useSystemDate is false
on sendCommandInTime theHandler,theTime
  convert theTime from time to seconds
  put theTime - the seconds into theSecondsToLapse
  if theSecondsToLapse > 0 then
    send theHandler to the target in theSecondsToLapse seconds
  end if
end sendCommandInTime
Call this handler as

Code: Select all

sendCommandInTime "yourHandler","4:00 PM"
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: triggering a handler at a specific time

Post by keram » Wed Mar 19, 2014 5:16 pm

Hi Mark,

Thanks for your reply.

It's not completely clear for me how to apply your solution so I'm guessing that this maybe how it should be(?):

Code: Select all

global gIncrement
local theTime
on mouseUp
  set the twelveHourTime to false
   if the hilite of btn "Radio1" is "true" then
      --      put (label of btn "everyhours" * 3600 + label of btn "everyminutes" * 60) into gIncrement
      put (label of btn "everyhours" + label of btn "everyminutes") into gIncrement --used for development
      
      if timerIncrement is not in the pendingMessages then -- don't pile up timerIncrement
         send "timerIncrement" to me in gIncrement seconds
      end if
   else
     put (label of btn "onhour" &":"& label of btn "onminutes") into theTime
      sendCommandInTime "nextLine",theTime
   end if
end mouseUp

on timerIncrement
   send "timerIncrement" to me in gIncrement seconds
   send mouseUp to btn "next"
end timerIncrement


    // theHandler: name of the command to be executed (no functions)
    // theTime: the time when to execute the command
    // assuming that useSystemDate is false
    on sendCommandInTime theHandler,theTime
      convert theTime from time to seconds
      put theTime - the seconds into theSecondsToLapse
      if theSecondsToLapse > 0 then
        send theHandler to the target in theSecondsToLapse seconds
      end if
    end sendCommandInTime

on nextLine
   send mouseUp to btn "next"
end nextLine

I guess it's correct since it works :)

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: triggering a handler at a specific time

Post by keram » Wed Mar 19, 2014 6:23 pm

Hi Mark,

I just discovered that you have replied on my last questions under wrong thread
http://ftp.runrev.com/forums/viewtopic. ... ff8#p99518

btn "Next" has this handler:

Code: Select all

global gAllLines,gCurrentLine

on mouseUp 
   if gCurrentLine >= the num of lines of gAllLines then
      exit mouseup
   end if
   
   add 1 to gCurrentLine
   put line gCurrentLine of gAllLines into fld "oneline"
   put gCurrentLine into fld "a"
    put gCurrentLine into gCurrentLine
   
end mouseUp
and handler "nextLine"

Code: Select all

on nextLine
   send mouseUp to btn "next"
end nextLine
Do I still need another button AMPM??
See my post just above.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: triggering a handler at a specific time

Post by Mark » Wed Mar 19, 2014 6:32 pm

Hi Keram,

Somehow, your posts come from a subdomain ftp.runrev.com instead of forums.runrev.com. It seems this mixes up things completely. I'll post the post that was supposed to be posted here first and will answer to your next post in another post :-)

Mark


Hi,

You'll need another button AMPM and this line:

put (label of btn "onhour" &":"& label of btn "onminutes" && the label of btn "AMPM") into theTime

Before I post a new script, I think I should ask you what does button "Next" do and what does handler "nextLine" do exactly? If they're not too long, perhaps you should also post the handlers of the button and the nextLine handler.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: triggering a handler at a specific time

Post by keram » Wed Mar 19, 2014 6:51 pm

Hi Mark,

Yes, there is something strange with these 2 domains...
But anyway you can find my reply here above.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: triggering a handler at a specific time

Post by Mark » Wed Mar 19, 2014 7:37 pm

Hi Keram,

Try this:

Code: Select all

global gIncrement
on mouseUp
   set the twelveHourTime to true
   if the hilite of btn "Radio1" is "true" then
      // assuming that labels of buttons contain integers 0-12 resp. 1-59.
      put (label of btn "everyhours" * 3600 + label of btn "everyminutes" * 60) into gIncrement
      if timerIncrement is not in the pendingMessages then -- don't pile up timerIncrement
         send "timerIncrement" to me in gIncrement seconds
      end if
   else
      // I assume the onhour and onminutes buttons to be the same as the every* buttons
      // and you need a button "AMPM" unless you make a 24-hours version
      put (the label of btn "onhour" &":"& the label of btn "onminutes" && the label of btn "AMPM") into theTime
      sendCommandInTime "nextLine",theTime
   end if
end mouseUp

on timerIncrement
   send "timerIncrement" to me in gIncrement seconds
   send mouseUp to btn "next"
end timerIncrement

on nextLine
   send mouseUp to btn "next"
end nextLine

// theHandler: name of the command to be executed (no functions)
// theTime: the time when to execute the command
// assuming that useSystemDate is false
on sendCommandInTime theHandler,theTime
   convert theTime from time to seconds
   put theTime - the seconds into theSecondsToLapse
   if theSecondsToLapse > 0 then
      send theHandler to the target in theSecondsToLapse seconds
   end if
end sendCommandInTime
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: triggering a handler at a specific time

Post by keram » Thu Mar 20, 2014 1:58 am

Hi Mark,
Mark wrote: // assuming that labels of buttons contain integers 0-12 resp. 1-59.
They have integers 0-24 resp 0-59 and 'set the twelveHourTime to false' is there.
Mark wrote:// and you need a button "AMPM" unless you make a 24-hours version
Yes, that's what I have - 24-hours version, so just this part '&& the label of btn "AMPM"' of the next line goes out.

It works great!
Thanks a lot for your help! :)

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Post Reply