I always seem to have trouble with timers. There is just
something missing from my understanding of them. This script goes
in a frame. It is supposed to play a sound after 30 seconds and
then wait for the user to push the spacebar to move on the user can
also hit "a" after 30 seconds to hear the sound again. The spacebar
and the "a" key shouldn't work for 30 seconds. I don't understand
the object part of the TimeOut. Here is my screwed up script:
-----------------------------------------
global gPitch
property pPitch

--wait 30 seconds and play sound
on exitFrame me
myTimer = timeOut("timer1").new(8000, #playPitch)
if keyPressed("a") then
sound(1).play(gPitch)
go to the frame
else if keyPressed(SPACE) then
go to next
else go to the frame
end if
end if

on exitFrame me
if myWaitDone = 0 then
if (_system.milliseconds > myWaitTime) then
myWaitDone = 1
sound(1).play(myPitch)
end if
else
if keyPressed("a") then sound(1).play(myPitch)
if keyPressed(SPACE) then
go next
exit
end if
end if
go to the frame
end

Too logical, I love it. (I knew that 30 seconds wasn't 8000,
but for testing I shortened it so I wouldn't have to wait so long
to see if it worked.) I never knew you could use pld instead of
list. I like that; it's clearer. I guess I still don't understand
TimeOuts and when to use them.

A timeout object runs independently of your other lingo code;
when you set the timeout object and it's parameters it immediately
begins the timing and calls the handler you specified every xxx
milliseconds based off the period you specified. There's really no
other magic to it than that.

> begins the timing and calls the handler you specified
every xxx
> milliseconds
..and calls the handler soon as director is idle, and the
timeout of xxx
milliseconds has expired. Thererfore, you shouldn't expect a
timeout to be
always on time. The 'period' is actualy the desired, or
minimum period.

> A timeout object runs independently of your other lingo
code;
Though these are director's internal stuff, I'd say that a
timeout doesn't
'run'. Timeouts are kept in a list and are checked when
director is idle (no
other script executing).

"Chunick" <webforumsuser@macromedia.com> wrote in
message
news:g2bg78$b68$1@forums.macromedia.com...
> Use timeouts in scripts that are not constantly
called... a timeout object
> is
> like the
http://en.wikipedia.org/wiki/Ron_Popeil
Showtime Rotisseries of
> Lingo,
> "Set it and forget it!"
>
> A timeout object runs independently of your other lingo
code; when you set
> the
> timeout object and it's parameters it immediately begins
the timing and
> calls
> the handler you specified every xxx milliseconds based
off the period you
> specified. There's really no other magic to it than
that.
>

Just trying to cater to my audience. I sacrificed a more
complete explanation for one that makes more sense and is a better
foundation for someone not as familiar with Director as you or I
might be, alchemist. Anyways, thanks for fleshing out the details,
nonetheless.