Sample Timer Scripts

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
gwildbur
Posts: 14
Joined: Wed Apr 25, 2012 11:57 pm

Sample Timer Scripts

Post by gwildbur » Fri Apr 27, 2012 6:58 pm

Being a complete beginner here I am wondering if anyone has a timer script built that will start a timer at a user supplied time, run at user supplied intervals and stop at a user supplied end time. I guess I could sit down and program this but thought I would ask if someone has already done something like this. It definitely would be a great time saver for me. The other thing that came to mind is to ask if there any resources that I could search for pre-written scripts.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Sample Timer Scripts

Post by dunbarx » Fri Apr 27, 2012 7:14 pm

You are absolutely correct. You should do this yourself. Once you get started, you will find continuous and specific help with all your issues.

Get going, and write back. Check out the "seconds" function, and its "see also" stuff, the "dateItems" keyword and its "see also", especially "convert".

Start with a repeat loop and test the seconds. Make sure you can get out of the loop.

Craig Newman

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Sample Timer Scripts

Post by mwieder » Fri Apr 27, 2012 7:20 pm

Agree with Craig in that you should try this yourself. Yes, it's something that everyone does and it would be simple to post some code that does this, but I think the process of your trying this out and posting questions when it doesn't work and then finally "getting it" will be the greatest time saver in the long run.

Hint:
In particular, check out the "send xxx in nn seconds" command.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Sample Timer Scripts

Post by jmburnod » Fri Apr 27, 2012 7:30 pm

Hi,

And also the pendingmessages function

Best

Jean-Marc
https://alternatic.ch

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

Re: Sample Timer Scripts

Post by Klaus » Fri Apr 27, 2012 7:39 pm

Hi gwildbur,

please check these stacks:
http://www.runrev.com/developers/lesson ... nferences/


Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sample Timer Scripts

Post by bn » Fri Apr 27, 2012 8:24 pm

Hi gwildbur,

if you are looking for an example of "send xxx in nn seconds" have a look at the Resource Center in the Help Menu of LiveCode.
Check -> Applications -> Displaying a count down (non-blocking). That can be used to make your timer, as has been suggested.

Also there are many scripts in the Resource Center you might be interested in.

Kind regards

Bernd

gwildbur
Posts: 14
Joined: Wed Apr 25, 2012 11:57 pm

Re: Sample Timer Scripts

Post by gwildbur » Fri Apr 27, 2012 9:00 pm

I appreciate all of the responses and while I agree that there is great learning to be had in creating my own timer, I am not a programmer and loops,nested loops etc. boggle my mind.
However I know that my learning curve suits editing rather than creating.
All that said if someone does have a timer script that they can share or if a donation is required I am open to that also.
Don't want to appear to be lazy but my passion is the design and layout of the app not in the detail of creating a new timer from scratch.
I have created a stack that enables a user to input start and stop times and also input how often to have the timer run and have included it if anyone is interested in using it.
Any help or suggestions would be gratefully accepted.
Attachments
UserTimeInput.rev.zip
(3.05 KiB) Downloaded 441 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Sample Timer Scripts

Post by dunbarx » Fri Apr 27, 2012 10:02 pm

Well, you are on your way. You did make a stack, and with a group, no less.

OK. Fine. You still have to do this yourself, but here is a head start. Make a button. Make three fields. Name one field "startTime". Name another "testTime". Name the third "Output".

Put this in the button script:

Code: Select all

on mouseUp
   put  word 1 of the long time into currentTime
   put word 1 of the long time into fld "startTime"
   convert currentTime to dateItems
   add 5 to item 6 of currentTime
   convert currentTime to  long time
   put  word 1 of currentTime into fld "testTime"
   put "The end is near" into fld "output"
   repeat until the mouseClick --just a safety
      put word 1 of the long time into fld "startTime"
      if fld "testTime" <= fld "startTime" then
         put "The end has come" into fld "outPut"
         exit to top
         end if
   end repeat
end mouseUp
After you get tired of watching it work, place a breakpoint right at the top, and step through line by line. The script is verbose, but that is so you can see better what is happening. Make this into a multi-level timer with several intervals.

Even if someone hands you a working gadget, it will lack what you need, and contain what you do not. The only way through this is to make it your way. This is a good thing.

You may find a new passion. Writing code is far richer than designing layouts. Write back. We all expect to hear from you often.

Craig Newman

townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

Re: Sample Timer Scripts

Post by townsend » Sat Apr 28, 2012 5:39 pm

Here's another Timer Sample. Drop this code into a button called start.
Make sure the label is also called "start" all in lower case.
The 10 second count is hard coded. Change it to whatever you want.

Code: Select all

local cntr, started

on mouseUp
     if the label of me = "start" then 
          set the label of me to "stop"
          call "countUp"
     else
          set the label of me to "start"
     end if
end mouseUp

on countUp
     if the label of me = "stop" then
          put the long seconds into started
          put (the long seconds - started) into cntr
          set the label of me to cntr
     else if cntr >10 then
          set the label of me to "start"
          beep
          exit to top
     else 
          put (the long seconds - started) into cntr
          set the label of me to cntr
     end if
     -- breakpoint
     send "countUp" to me in 0.20 seconds
end countUp

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

Re: Sample Timer Scripts

Post by Klaus » Sat Apr 28, 2012 6:21 pm

Hi guys,

no need to CALL this handler, since it is in the current message hierarchie :)

Code: Select all

on mouseUp
     if the label of me = "start" then 
          set the label of me to "stop"
          ##!!!
          countUp
     else
          set the label of me to "start"
     end if
end mouseUp

## Here it is :-)
on countup
... 
Best

Klaus

Post Reply