"Activity" message ?

Kay C Lan lan.kc.macmail at gmail.com
Sun May 17 23:13:21 EDT 2009


On Fri, May 15, 2009 at 11:02 PM, Jacques Hausser
<jacques.hausser at unil.ch>wrote:

>
> Yes it is tempting. As the timer runs in the background, this front script
> should reinitialize a GRemainingTime global (or a CP if you are
> globalophobic - I'm not). But, depending of what the user is doing, I want
> to set different values for the reinitialisation, therefore a second global
> or CP...
> I'll look. Many thanks anyway.
>
> Probably a little late, but what about handling this in reverse. In every
user action script, start with a 'cancel' command and at the end of every
script finish with a 'send' command.

The idea is that at the end of the user doing something, the script will
automatically instigate the reinitialisation in a given time, say:

send myReinit to stack "myStack" in 300 sec

At the beginning of a script where the user has done something, the script
will cancel the reinitialisation:

cancel item 1 of the last line of the pendingMessages

For different actions you can have different send in times, ie if it opens a
field full of text it might be 600 sec, but if it activates a 2 sec sound
bite you might send in 60 sec.

The only tricky bit is that for the very first action there is no
pendingMessage to cancel, and, although you theoretically should never get
out of sync it might be worthwhile using an all encompassing cancel
function, something like:

FUNCTION reInitMonitor
  --if no pending messages, nothing happens
   repeat until the pendingMessages is empty
      cancel item 1 of line 1 of the pendingMessages
    end repeat
end reInitMonitor

THIS ASSUMES YOU ARE NOT USING 'SEND' FOR SOMETHING ELSE!!!! If you are,
then you'd need to keep track of the send ID and only cancel the appropriate
IDs.

So in summary:

on mouseUp
  --cancel any impending reinitialisation
  reInitMonitor

  --do all your stuff here

  --set up a new reinitialisation
  send myReInit to stack "myStack" in 300 sec
end mouseUp

Look in the Dictionary under, cancel, send and pendingMessages

HTH



More information about the use-livecode mailing list