Yes, the problem is that when you have a tight repeat loop as you
show, everything is locked out until that loop ends. Your
description of a solution is exactly what I would suggest. If you
are into OOP, build a single CommandProcessor object which maintains
a list of commands and a state property variable. Use timeout
objects for timing. Something like this (completely untested -
skeleton code):
property psymState -- #idle or #busy
property pllCommands -- property which is a list of lists of commands
-- each command has a name, and
optional params
on new me
pllCommands = []
psymState = #idle
add(the actorList, me)
end
-- Call this to add "commands" to your processor
-- call it with #wait, 100 to wait 100 milliseconds
on mAddCommand me, symName, param1, param2, param3, etc.
-- build up a list of this command and its parameters
lCommand = [symName]
nParameters = the paramCount
repeat with i = 3 to nParameters
append(lCommand, param(i))
end repeat
-- and add it to the list of all commands
append(pllCommands, lCommand)
end
-- Since your object is in the actorList, this handler is called on
every frame event
on stepFrame me
if symState = #busy then
return
end if
if count(pllCommands) = 0 then
return
end if
lCommand = pllCommands[1] -- pull first thing off the list
deleteAt(pllCommands, 1) -- and delete it
symCommand = lCommand[1]
case symCommand of
#wait:
howlong = lCommnd[2]
timeout("MyTimeout").new(howlong, #mTimeoutCallBack)
symState = #busy
#SomeFunkyCommand:
-- pull out params and do whatever this command says to do
#SomeOtherCommend:
-- pullout params and do this type of command
otherwise:
Alert("Unrecognized command" && symCommand)
end case
end
on mTimeOut me
-- timeout has ended
-- do whatever you need to do
symState = #idle
end
-- More code to handle your other commands
Hope this helps.
Irv
At 4:26 PM -0400 6/27/01, Dennis Flood wrote:
>Hello all,
>
>I think I'm hitting the wall here. I've got a bunch of objects which do some
>serial port stuff on different ports. The nature of the thing is that I've
>got to put some delays between certain functions to allow receiving devices
>to have the time to process commands. These are long lists of processes
>which require some logic decisions based on responses from the serial
>devices.
>
>Right now I've got this, which for one object, does the job:
>
>on waitLoop me,num
> startOfWait = the milliseconds
> repeat while the milliseconds < (startOfWait + num)
> nothing
> end repeat
>end
>
>Problem is this handler stops everybody. I found something on DOUG, but that
>won't stop the calling script.
>
>Has anyone ever created something like this that only stops the calling
>handler from executing.
>
>I'm imagining re-coding using a scheme where I take all my code for these
>routines and create a list with "commands" which execute each step in the
>code. I'd then create a list processing engine that could be stopped and
>restarted by tracking the position in a variable and starting a timeout
>object when it encountered a wait command.
>
>Just seems like there should be an easier way.
>
--
Lingo / Director / Shockwave development for all occasions.
(Home-made Lingo cooked up fresh every day just for you.)
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]