Hi all,
I want a progress bar (0 to 100) to tick down to 0 in about 2 seconds. At a thumbPos of 0, a buzz will sound indicating an error. The way to stop the progress bar is to respond to the card with a 'y' or 'n' keypress. I've been trying this for over a day now to no avail. Source code is below. Any help would be appreciated. Thanks!
on openCard
global thisKey
set the beeppitch to 60
put the thumbposition of scrollbar "progress" into newThumbPosition
put the ticks into startTicks
repeat until thisKey = 'n' or thisKey = 'y'
--put (the ticks - startTicks) into timer
--if timer mod 500 = 0 then
put the thumbposition of scrollbar "progress" into newThumbPosition
put newThumbPosition - 1 into newThumbPosition
if newThumbPosition < 0 then put 0 into newThumbPosition
set the thumbposition of scrollbar "progress" to newThumbPosition
--end if --timer
end repeat
if newThumbPosition = 0 then
put true into tooLate
-- repeat for 1 second --until thisKey = 'y' or thisKey = 'n'
-- beep
-- end repeat
end if --0
end openCard
Progress bar question
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
You don't seem to have a test in the code for a key being down, I'm not sure where you're setting the value of "thisKey"
I'd tackle this by using a "send in time" approach rather than a loop. Repeat loops are blocking structures and it can sometimes be difficult to get the keyboard to be read in between the iterations of the loop.
Try something like this:
In the scrollbar itself, put this code
In the card script, put:The timing isn't perfectly accurate to the millisecond, it takes about 2025 to 2030 milliseconds to run on my laptop.
On the card, the rawKeyDown codes 121, 110, 89, and 78 are the values returned by "y" and "n" with and without a Caps key held down. If any of those keys are down, then the global variable gFlag will be set to false.
In the scrollbar handler, the next iteration of the cmdElapseTimer handler will only be "sent" if the gFlag is true, and so your loop will be stopped, as it will if the progress bar reaches the end limit.
HTH
I'd tackle this by using a "send in time" approach rather than a loop. Repeat loops are blocking structures and it can sometimes be difficult to get the keyboard to be read in between the iterations of the loop.
Try something like this:
In the scrollbar itself, put this code
Code: Select all
global gFlag
on cmdElapseTimer
local tTimer
put the thumbPosition of me into tTimer
if gFlag is true and tTimer > 0 then
subtract 2.5 from tTimer
set the thumbPosition of me to tTimer
send "cmdElapseTimer" to me in 50 milliseconds
else
beep
end if
end cmdElapseTimer
Code: Select all
global gFlag
on openCard
put true into gFlag
set the thumbPosition of scrollbar "progress" to 100
send cmdElapseTimer to scrollbar "progress"
end openCard
on rawKeyDown theKey
put not (theKey is in "121,110,89,78") into gFlag
pass rawKeyDown
end rawKeyDown
On the card, the rawKeyDown codes 121, 110, 89, and 78 are the values returned by "y" and "n" with and without a Caps key held down. If any of those keys are down, then the global variable gFlag will be set to false.
In the scrollbar handler, the next iteration of the cmdElapseTimer handler will only be "sent" if the gFlag is true, and so your loop will be stopped, as it will if the progress bar reaches the end limit.
HTH