Page 1 of 1

Timed Traytip

Posted: 08 Jun 2017, 13:47
by c4p
The help file suggest the Traytip command display time "may vary from the one specified."
Using the example in the help file as a starting point, I was trying to brute force Traytips to display for the actual desired time.

Code: Select all

TrayTip(traytitle :="", traytext := "", traysecs := 3, trayoptions := "") {
  SetTimer, RemoveTrayTip, % (traysecs * -1000)
  SetTimer, RefreshTrayTip, 1000

  RefreshTrayTip:
  TrayTip, %traytitle%, %traytext%, %traysecs%, %trayoptions%
  return
   
  RemoveTrayTip:
  SetTimer, RefreshTrayTip, Off
  TrayTip
  
return
}
The traytip displays as you fall through the function the first time, but timer calls to RefreshTrayTip do not have the data within the traytext,etc (because the were local to the function). I tried declaring them global without success.

so my question is how to access parameters of a function, outside that function? I'm sure it is something related to my lack to good understanding of variable scope. Thanks for you consideration.

Re: Timed Traytip

Posted: 08 Jun 2017, 13:51
by Nightwolf85
What if you declare them as Static

Code: Select all

TrayTip(traytitle :="", traytext := "", traysecs := 3, trayoptions := "") {
	Static title, text, secs, options
	
	title := traytitle
	text := traytext
	secs := traysecs
	options := trayoptions
	
  SetTimer, RemoveTrayTip, % (secs * -1000)
  SetTimer, RefreshTrayTip, 1000

  RefreshTrayTip:
  TrayTip, %title%, %text%, %secs%, %options%
  return
   
  RemoveTrayTip:
  SetTimer, RefreshTrayTip, Off
  TrayTip
  
return
}
I'm not sure if its necessary to use other variables, and I didn't test, just a thought.

Re: Timed Traytip

Posted: 08 Jun 2017, 14:23
by c4p
no go on statics
BTW, always disliked timers forcing subroutines instead of functions with arguments.

Re: Timed Traytip

Posted: 08 Jun 2017, 14:56
by c4p
took another approach which works but the flicker is unacceptable, and even if my first attempt made to work, it would flicker too.

Code: Select all

TrayTip(traytitle :="", traytext := "", traysecs := 3, trayoptions := "") { ;------------------------------------------------------------------------------
    Loop % traysecs
    {
        TrayTip, %traytitle%, %traytext%, %traysecs%, %trayoptions%
        sleep,  1000
    }
    TrayTip
return
}