Page 1 of 1

Timer that repeats - New Question

Posted: Sat May 16, 2015 6:02 pm
by L.Coder
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.

Re: Timer that repeats - New Question

Posted: Mon May 18, 2015 3:53 am
by dunbarx
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

Re: Timer that repeats - New Question

Posted: Mon May 18, 2015 4:48 pm
by jacque
Be aware that Craig's script is blocking. That is, no other user actions will be allowed until the script completes.

Re: Timer that repeats - New Question

Posted: Mon May 18, 2015 6:08 pm
by dunbarx
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

Re: Timer that repeats - New Question

Posted: Mon May 18, 2015 10:28 pm
by L.Coder
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:

Re: Timer that repeats - New Question

Posted: Tue May 19, 2015 5:18 am
by dunbarx
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

Re: Timer that repeats - New Question

Posted: Tue May 19, 2015 6:02 am
by jacque
Everyone else, keep your distance.
I had to laugh. :-)

Anyway, in this case I think your approach is valid.

Re: Timer that repeats - New Question

Posted: Wed May 20, 2015 11:32 pm
by L.Coder
hahahahaha Thanks Craig!!! You help me so much. :o