[comp.sys.mac.hypercard] Idling in pre-2.0 HC

mike@pyrite.SOM.CWRU.Edu (Michael Kerner) (01/10/91)

AAAAAAugh!

Howdy, folks, I have a slight little problem I'm trying to work on:
I want to run something similar to a screen saver (actually, the idea is
similar - if HC is idle for so long I want to do something).

Well, the most straightforward (at least to me) idea was
on idle
   put 1 into i 
   repeat while idle
         add 1 to i
         if i > someValue then
            blah blah
         end if
   end repeat
end idle

however, no go.  Any other ideas/ suggestions?

Thanks,
Mike.
Body by Nautilus...Brain by Mattel.

clarson@ux.acs.umn.edu (Chaz Larson) (01/10/91)

In article <1991Jan10.142922.11037@usenet.ins.cwru.edu> mike@pyrite.SOM.CWRU.Edu (Michael Kerner) writes:
|the idea is
|if HC is idle for so long I want to do something.
|
|Well, the most straightforward (at least to me) idea was

There's a basic problem here in the way you're using "idle".  It's a message,
not a property or variable.

|on idle
|  put 1 into i	
|  repeat while idle	<-- this line is trouble	
|        add 1 to i
|        if i > someValue then
|           blah blah
|        end if
|  end repeat
|end idle
|
|however, no go.  Any other ideas/ suggestions?

This script will always choke on the problem line above with an "Expected true
or false here" error.

What you want is something like this:

on idle
  global delay_time
  add 1 to delay_time
  if delay_time > 10 then
   --do whatever you want 
  end if
end idle

Line by line here's what it does:

on idle
	The "idle" message invokes the handler
  global delay_time
	This sets up a global variable "delay_time", which will hang around
	between invocations of the "idle" handler.  If "delay_time" already
	exists, as it will on the second, third, etc pass through the handler,
	this tells the script to use the existing "delay_time" instead of
	setting up a new one.
  add 1 to delay_time
	Adds one to the "delay_time" variable, to count how many times we
	have been through this handler.
  if delay_time > 100 then
   --do whatever you want
  end if
	You'd replace 100 with an appropriate number and fill in your code.
end idle

Hope this helps ---  Hmmm, I seem to be afflicted with that dread disease,
Male OverExplaining Syndrome...

chaz

 
-- 
Someone please release me from this trance.
clarson@ux.acs.umn.edu                                       AOL:Crowbone

ollef@sics.se (Olle Furberg) (01/11/91)

In <1991Jan10.142922.11037@usenet.ins.cwru.edu> mike@pyrite.SOM.CWRU.Edu (Michael Kerner) writes:
 
>AAAAAAugh!

  Ta det lungt. Ta en TOY!

>Howdy, folks, I have a slight little problem I'm trying to work on:
>I want to run something similar to a screen saver (actually, the idea is
>similar - if HC is idle for so long I want to do something).

  As I understand it you must *pass* the idle to all other sort of scripts
and especially to HyperCard itself. 

  The idea of a "screen saver" written in HyperTalk is doomed to failure:
as soon you get a dialog (like ask or answer), you could in no way dispose
it through HyperTalk. It could be argued that it should be built in into
HC some sort of "TimeForSomethingCompletelyDifferent"-message (together 
with a global property "EnoughTime"), but I will not do it here.

  My primitive solution is to look if the user changes the location
of the mouse, and stores the mouselocation and the ticks into a
global variable. I update this variable for every keydown or change in
mouselocation. It's a small script and looks like this:


on idle
  global theidle
  get theidle
  delete last item of it
  if the mouseloc is it then
    if (the ticks - the last item of theidle > 100) then
      answer "Get back to work!"
      put the mouseloc & "," & the ticks into theidle
    end if
  else
    put the mouseloc &"," &the ticks into theidle
  end if
  pass idle
end idle

on keydown
  global theidle
  put the ticks into last item of theidle
  pass keydown
end keydown




   /Olle