Timer that repeats - New Question

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
L.Coder
Posts: 15
Joined: Mon May 04, 2015 12:34 am

Timer that repeats - New Question

Post by L.Coder » Sat May 16, 2015 6:02 pm

Hi, I´m being working in a timer since a few days ago and I´m trying that my timer repeats.

For example, My timer counts 30 seconds and if I press a button that says 6 on it I want that my timer counts 30 seconds 6 times. How can I do that?

postscript: sorry if you can't understand me so well , I do not master English very well.

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

Re: Timer that repeats - New Question

Post by dunbarx » Mon May 18, 2015 3:53 am

Hi.

Does this give you some sort of clue? Make a buttons and a field. In the button script:

Code: Select all

on mouseUp
   startTimer 6
end mouseUp
In the card script:

Code: Select all

on startTimer numberOfRepeats
   repeat numberOfRepeats
      repeat with y = 1 to 3
         put y into fld 1 
         wait 1 second
      end repeat
   end repeat
end startTimer
I made the timeout "3" instead of "30" so you can see it complete without having to wait three minutes. But I hope you get the idea.

Now then, please write back and tell me why the timer handler is in the card script. And then tell me why this is a good idea, especially if you have several different buttons, each of which might have a different value to repeat.

Craig Newman

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

Re: Timer that repeats - New Question

Post by jacque » Mon May 18, 2015 4:48 pm

Be aware that Craig's script is blocking. That is, no other user actions will be allowed until the script completes.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Timer that repeats - New Question

Post by dunbarx » Mon May 18, 2015 6:08 pm

Jacque makes a point. So think about this in the button script:

Code: Select all

on mouseUp
put 0 into fld 1
startTimer 6
end mouseUp

on startTimer numberOfRepeats
   if numberOfRepeats = 0 then exit to top
   if fld 1 = 30 then
      put 0 into fld 1
      subtract 1 from numberOfRepeats
      end if
   add 1 to fld 1 
   send "startTimer" && numberOfRepeats to me in 10 --60 ticks = 1 second, the '10" is just so this handler does not take all day
end startTimer
This sort of construction releases the program to the user. You might also learn about the "wait with messages" command, another useful way to do this.

Craig

L.Coder
Posts: 15
Joined: Mon May 04, 2015 12:34 am

Re: Timer that repeats - New Question

Post by L.Coder » Mon May 18, 2015 10:28 pm

Hi, Craig & Jacque you helped me a lot, it works perfectly!

But just another question:

I put just 1 button to play the timer, and I want that when I press the button depends, that what number says in a label, be the times that the timer will repeat. How can I implement the code that you gave me?

Regards| :lol: :idea:

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

Re: Timer that repeats - New Question

Post by dunbarx » Tue May 19, 2015 5:18 am

Hmmm.

I do not want to get into trouble with my fellow wizards. Oh, the hell with them.

You will recall that in the handler above, there was an explicit "6" set as a parameter to the command call. That value can come from anywhere, you know. What would happen if you set a property of that button, as you say, perhaps, its "label", to something useful to your purpose? In other words, when you click on the button, try to think of a way to use that property to set the value you want. What would you have to do in the handler to pull a value from the button, and then use that value to proceed?

Everyone else, keep your distance.

Craig

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

Re: Timer that repeats - New Question

Post by jacque » Tue May 19, 2015 6:02 am

Everyone else, keep your distance.
I had to laugh. :-)

Anyway, in this case I think your approach is valid.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

L.Coder
Posts: 15
Joined: Mon May 04, 2015 12:34 am

Re: Timer that repeats - New Question

Post by L.Coder » Wed May 20, 2015 11:32 pm

hahahahaha Thanks Craig!!! You help me so much. :o

Post Reply