round timer

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
lewisbates1991
Posts: 3
Joined: Wed Jan 23, 2008 4:59 pm

round timer

Post by lewisbates1991 » Wed Jan 23, 2008 5:06 pm

i want to make software with a digital timer and when you press a start button the timer starts then after 2 minutes it makes a sound then after three minutes it makes a differnt sound etc etc.only thing is where do i start?

deeverd
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 165
Joined: Mon Jul 16, 2007 11:58 pm

Post by deeverd » Wed Jan 23, 2008 6:26 pm

Hello lewisbates1991,

I won't claim to be a great expert here, but the following code will work adequately:

Code: Select all

global gCancelLoop
  global gTotal


on mouseUp
   
  repeat with i = 1 to 300 -- Note: (300 seconds = 5 minutes)
    put i into field "secondsReadout" -- You'll need to make a field with the names of "secondsReadout" and "minutesReadout"
    put 1 into tSeconds
    add 0 to field "minutesReadout" -- Note: This line puts a zero in the minutes field at the start.
    put i into tMinute
    divide tMinute by 60
    --set the numberFormat to "#." Note:  The number of hashmarks to the right of the decimal point equals the number of places it will show.
    --put the trunc of tMinute into field "minutesReadout"  Note:  Trunc rounds down a number so that it only shows the whole number and ignores the fraction.
    add tSeconds to gTotal
    put gTotal into field "totalSeconds" -- if you want to watch the countdown and see the total number of seconds elapse.
    
    if i = 60 then 
      add 1 to field "minutesReadout"
      put empty into i
    end if
     
    if gTotal = 120 then
      beep(2)
    end if
    
    if gTotal = 300 then 
      beep(3)
      # Note: you might want to have a wav file here instead with script such as...
      -- play audioClip "alarm.wav"
    end if
    
    
    wait 1 second with messages 
    if gTotal = tTimerSet then put true into gCancelLoop
    if gCancelLoop is true then exit repeat
     
  end repeat
   
  put empty into gTotal
  put false into gCancelLoop
   
  
end mouseUp
If you want a button that stops the timer, here's the code, too:

Code: Select all

global gCancelLoop

on mouseUp
  put true into gCancelLoop
end mouseUp
Hope this helps. All the best, deeverd

lewisbates1991
Posts: 3
Joined: Wed Jan 23, 2008 4:59 pm

Post by lewisbates1991 » Wed Jan 23, 2008 9:44 pm

ok thanks that worked but when the sound plays it only plays for that 1 seconds how can i make it play it unti its finshed but keep the timer going

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Wed Jan 23, 2008 10:33 pm

Hi,

for something like this I really recommend using a send in time structure. An interesting read on the topic of clockfaces is this:

http://www.inspiredlogic.com/beautiful/clockface.html

Hope that helps a bit,

Malte

lewisbates1991
Posts: 3
Joined: Wed Jan 23, 2008 4:59 pm

Post by lewisbates1991 » Wed Jan 23, 2008 11:21 pm

the is what i want but on my desktop aviable off line and with a differnt name http://www.speedbagforum.com/timer.html

paul_gr
Posts: 319
Joined: Fri Dec 08, 2006 7:38 pm

Post by paul_gr » Thu Jan 24, 2008 1:21 am

On that site the author shows you how to use it offline.
Changing the name would be trivial.

Rebuilding it using Rev would be a bit of work but not difficult.
Have you managed to get some of it working in rev yet?

Paul
Last edited by paul_gr on Thu Jan 24, 2008 6:48 pm, edited 1 time in total.

deeverd
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 165
Joined: Mon Jul 16, 2007 11:58 pm

Post by deeverd » Thu Jan 24, 2008 4:35 pm

Hello lewisbates1991,

I wanted to get back to you on the sound issue. The best way I've found so far to keep the program running while the alarm is going is to use a wav file (assuming you're using Windows.) However, should you decide to have a different audioClip for each of your two alarms, there's a little trick you need to know about. If you try running two different audioClips in the same script, usually the first one will play and then you'll just hear sort of a "thunk" when the other one should have worked. Here's the script I use to overcome that problem:

Code: Select all

global soundCount 
global soundList 
 

on mouseUp
  
  put 1 into gSoundCount 
  
  put "firstAlarm.wav, secondAlarm.wav" into gSoundList
The two global variables should be placed under the global variables I put in the original timer script I sent, and then the first two lines of script under the "on mouseUp" handler should be placed right under the "on mouseUp" of the original script.

In this example, I have two .wav file examples, but you can obviously rename them to the names of your own sound files of alarms. There's a lot of sources for such sound files, and certainly a big source is the online Microsoft office clipart site. Keep in mind, however, most sound files you download, even with a .wav extension are not usually the real thing. The best bet is to also download the free sound file converter program from "Audacity" and convert any audioClip to a true .wav format that Revolution can use.

As for keeping an alarm running the entire duration between the 2 minute and five minute settings, which I think is what you want, as long as you know the time duration of your .wav file, you can simply make it repeat for as long as you need. For example, if I wanted the first alarm to loop for three minutes and I knew the audioClip itself was exactly 5 seconds long, I'd probably tell it to repeat for (36) times. There might be a better way but this is just off the top of my head. By the way, when the second audioClip is activated, it should stop the first alarm the moment it goes into the second alarm, unless you write script that specifically tells it to wait until the first alarm is finished.

Here's another thought: You might want to save your stack as a palette with script such as the following:

Code: Select all

on preOpenCard
  save stack "fiveMinuteTimer" as palette
end preOpenCard

There's a number of ways you can turn a stack into a palette, but however you do it, once it's a palette it will float above your other stacks so it will be accessible for use. You also have to reset it to "topLevel" before you can edit it again after turning it into a palette.

Anyway, I hope all this helps. Now I need to go to the website that Malte pointed you toward and learn about that better way, too.

Cheers, deeverd

Post Reply