Timers interfering with eachother

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Darkthornex
Posts: 6
Joined: 17 Nov 2017, 16:30

Timers interfering with eachother

18 Nov 2017, 15:36

;im not sure why its happening but timer 2 and 3 seem to be combining into one,
; what happens when i run the script is it runs on timer 3s time frame but sends both 2 and 3 commands
;timer 2 doesnt seem to go off at all
#Persistent
GoSub, MyTimer1 ;Call it once, then it sets it self to run every 300.0 to 500.0 seconds;

GoSub, MyTimer2 ;Call it once, then it sets it self to run every 13.0 to 20.0 seconds;

GoSub, MyTimer3 ;Call it once, then it sets it self to run every 65.0 to 85.0 seconds;

return

MyTimer1:
critical
Send, ,chop {enter 1}
Send, ,mine {enter 1}
Send, ,forage {enter 1}
Send, ,fish {enter 1}
Random, Time_To_Wait, 300.0, 500.0 ;
SetTimer, MyTimer1, % Time_To_Wait * -1000 ;

MyTimer2:
critical
Send, ,adv {enter 1}
random, time_to_wait, 12.0, 25.0 ;
SetTimer, Mytimer2, % Time_To_Wait * -1000 ;

MyTimer3:
critical
Send, ,heal auto{enter 1}
Send, ,pheal auto {enter 1}
random, time_to_wait, 65.0, 85.0 ;
SetTimer, Mytimer2, % Time_To_Wait * -1000 ;

return

Esc::ExitApp
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Timers interfering with eachother

18 Nov 2017, 16:14

Your 2nd and 3rd timers are resetting the 2nd timer, nothing is resetting the 3rd.

Besides that, try this.

Code: Select all

#SingleInstance,Force
gosub,A
gosub,B
gosub,C
return
A:
	All_Timers.="A "
	Tooltip,% All_Timers
	Random,Time1,5,7
	SetTimer,A,% Time1*-1000
	return
B:
	All_Timers.="B "
	Tooltip,% All_Timers
	Random,Time1,8,10
	SetTimer,B,% Time1*-1000
	return
C:
	All_Timers.="C "
	Tooltip,% All_Timers
	Random,Time1,11,13
	SetTimer,C,% Time1*-1000
	return	
Esc::ExitApp
Darkthornex
Posts: 6
Joined: 17 Nov 2017, 16:30

Re: Timers interfering with eachother

18 Nov 2017, 16:29

im not sure if i understand completely i am very new to coding and have been working on this since i started 3 days ago,
could you give me an example of how to combine both your example and my script so i can study it?
ive done alot of searching on the subject but nothing turned up
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Timers interfering with eachother

18 Nov 2017, 17:02

Darkthornex wrote:im not sure if i understand completely i am very new to coding and have been working on this since i started 3 days ago,
could you give me an example of how to combine both your example and my script so i can study it?
ive done alot of searching on the subject but nothing turned up
Did you see your problem here?
Darkthornex wrote:MyTimer3:
critical
Send, ,heal auto{enter 1}
Send, ,pheal auto {enter 1}
random, time_to_wait, 65.0, 85.0 ;
SetTimer, Mytimer2, % Time_To_Wait * -1000 ;
in "MyTimer3" you are setting "MyTimer2"


As for the script I posted, it is just a easy way for you to test/see what is going on with your script.

To use my example, comment out all your code in the timers that send keystrokes etc and add in a tooltip to track how each timer is getting ran.
here is an example using your first timer. You can do the same to the other 2.

Code: Select all

MyTimer1:
critical
All_Timers.="1 "  ;<---------- Put a 2 in timer 2 and a 3 in timer 3
Tooltip,% All_Timers
;Send, ,chop {enter 1}
;Send, ,mine {enter 1}
;Send, ,forage {enter 1}
;Send, ,fish {enter 1}
Random, Time_To_Wait, 300.0, 500.0 ;  <--------------You might want to make the times shorter to do your testing.
SetTimer, MyTimer1, % Time_To_Wait * -1000 ;
return  ; <---------------------------- Oh yeah, you need to add a return to your labels or they will run the other labels too.
Darkthornex
Posts: 6
Joined: 17 Nov 2017, 16:30

Re: Timers interfering with eachother

18 Nov 2017, 17:24

I didn't see your reply but i tried using your script that you gave me and modified it to my needs and it seems to work amazingly
i was just wondering what the best way to add a hotkey to start the script would be
also does the random timer select one or other, or does it pick a random one between the two
#NoEnv
#SingleInstance,Force
gosub,A
gosub,B
gosub,C
return
A:
Send, ,chop {enter 1}
Send, ,mine {enter 1}
Send, ,forage {enter 1}
Send, ,fish {enter 1}
All_Timers.="A "
Tooltip,% All_Timers
Random,Time1,300.0,500.0
SetTimer,A,% Time1*-1000
return
B:
Send, ,adv {enter 1}
All_Timers.="B "
Tooltip,% All_Timers
Random,Time1,12.0, 20.0
SetTimer,B,% Time1*-1000
return
C:
Send, ,heal auto {enter 1}
Send, ,pheal auto {enter 1}
All_Timers.="C "
Tooltip,% All_Timers
Random,Time1,65.0, 85.0
SetTimer,C,% Time1*-1000
return
Esc::ExitApp
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Timers interfering with eachother

18 Nov 2017, 17:49

Darkthornex wrote:i was just wondering what the best way to add a hotkey to start the script would be
To have a hotkey start everything, just take the 3 "gosubs" and move them to a hotkey

Code: Select all

*F1::
	gosub,blah
	gosub,blah2
	gosub,blah3
	return
Also, you should change the names of the labels back to something other than a single letter,
you likely won't have any problems with them being just a single letter, but it is a bad habit to do that.
The name of your labels and variables should be somewhat related to what they do/are/hold etc.
I know that I used single letters, but that was just a example, and I was trying to be as plain as I could be.
Darkthornex wrote: also does the random timer select one or other, or does it pick a random one between the two


The random numbers were your creation, did you want the timers to be launched randomly? I don't think that is what you were going for. So I would say no?
You had the time between each instance of the timers random, if you don't want them to be random, then remove the random number generator and set fixed times.
There is no issues if you leave then as random.

just so you are clear about moving the gosubs, your script should start with your

Code: Select all

#NoEnv
#SingleInstance,force
;w/e
;w/e
;w/e
return  ;<-------------------------  After this return you add your timer labels, and after them you can add your start hotkey and exitapp hotkey
One last thing. Please do everyone a favor and use the code thingamajigger to post code.
You are making me have to remember when I had to read and write code in notepad...
Darkthornex
Posts: 6
Joined: 17 Nov 2017, 16:30

Re: Timers interfering with eachother

18 Nov 2017, 18:09

Thank you so much, you've been a great help, and ill be sure to use the code paste thingy next time i need help, its funny thought because im currently writing all my stuff in notepad, cant thank you enough for all the help
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Timers interfering with eachother

18 Nov 2017, 18:42

Darkthornex wrote:Thank you so much, you've been a great help, and ill be sure to use the code paste thingy next time i need help, its funny thought because im currently writing all my stuff in notepad, cant thank you enough for all the help
If you plan on doing more scripting I suggest that you get a better editor. I used notepad for the first 8-9 months of scripting and then I looked for something better and the difference is night and day. I personally use "Scite4AutoHotkey" but there are some other ones worth looking into.

I also do AutoHotkey tutorials on YT if you are looking for more help getting started in a variety of topics. I currently have about 200-300 videos covering many things AHK.
just search for "CivReborn". Anyway good luck with your script.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, doanmvu, Google [Bot], haomingchen1998, Peiya, rubeusmalfoy and 146 guests