Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Set timer inside of function to reset


  • Please log in to reply
2 replies to this topic
Tito
  • Members
  • 13 posts
  • Last active: Dec 14 2015 12:03 PM
  • Joined: 10 Nov 2012

I made wrote these lines of code but I have no idea how to add a timer to set my variable to some default value.

 

This is what I want:

 

- Everytime the function is called a variable is set to something.

- After that a timer will run for 4 seconds

- when the timer runs off the variable is set to a default value (e.g. -1 or something)

 

This is what I got so far, but no idea how to implement the timer.

myfunc(key)
{
global myVar = key

;timer code
;if timer runs off
;set myVar to -1
}


Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013
global myVar



1::myfunc(3)
2::ToolTip % myVar




myfunc(key)
{
    myVar := key
    SetTimer, resetVar, -4000
}

resetVar()
{
    myVar := -1
}


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

You can have the timer routine inside function as well:

global myVar

1::myfunc(3)
2::ToolTip % myVar

myfunc(key){
	myVar := key
        SetTimer, resetVar, -4000
	return

	resetVar:
	  myVar:=-1
	return
}