How do I run two sequences after each other and then loop back to the first Topic is solved

Ask gaming related questions (AHK v1.1 and older)
TGX
Posts: 8
Joined: 24 Apr 2021, 02:46

How do I run two sequences after each other and then loop back to the first

08 May 2021, 20:05

Once again I apologise at my ability to grasp how this works, if anyone has time to help I would appreciate it.

{F9} to start the script

Sequence 1:
hold the {a} key down, and also tap the {x} key every 200ms

Sequence 2:
hold the {b} key for 2 seconds then release
press {enter}, wait 2 second
press {enter}, wait 5 seconds
press {enter}, wait 10 seconds
press {enter}, wait 2 second
press {up} arrow, press {enter}, wait 10 seconds
press {esc} three times, press {enter}, wait 5 seconds

I would like sequence 1 to run for 30 minutes then stop, wait 30 seconds in case the game is finishing something off, then run sequence 2. After the last 5 second wait in sequence 2 I would like it to loop around to run sequence 1 again for 30 minutes and sequence 2 after, etc, etc.

Ideally I would like to be able to stop this by pressing {F10} whenever I needed too and have it start over again when I press {F9} again, I don't need it to finish it's current process or resume where it left off or anything. {F10} would be like a stop and reset type thing.


Hope that makes sense and someone has time to help.

Thanks in advance.
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: How do I run two sequences after each other and then loop back to the first

08 May 2021, 20:51

Here is a way to get started. May need some adjustments.

Code: Select all

F10::Reload
F9::
SoundBeep, 1500
Send {a down}
SetTimer, Stop, % -1000 * 60 * 30
SetTimer, X, 200
Return

Stop:
SetTimer, X, Off
Send {a up}
SoundBeep, 1000
Sleep, 30000
Send {b down}
Sleep, 2000
Send {b up}
For k, v in [2, 5, 10, 2] {
 Send {Enter}
 Sleep, v * 1000
}
Send {Up}{Enter}
Sleep, 10000
Send {Esc 3}{Enter}
Sleep, 5000
Gosub, F9
Return

X:
Send x
Return
TGX
Posts: 8
Joined: 24 Apr 2021, 02:46

Re: How do I run two sequences after each other and then loop back to the first

09 May 2021, 03:05

Thank you for putting the time in to do that, I haven't been able to test the latter sequence fully yet as although it starts off fine, but after the first fight the game acts as if {a} has been released, which I don't believe is a fault of the script it is simply how the game handles inputs.

The simplest workaround to that I can think of, coming from someone who has no idea if this would be easy to do or not, would be to alter the holding of {a} in sequence 1 to a 5 second hold, which is then released and held again straight away. So after the fight finishes if it doesn't register {a} as being pressed the script will automatically release and re-hold {a} shortly anyway resolving that issue.

Again, I apologise about my explanations and thank you in advance once again.
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: How do I run two sequences after each other and then loop back to the first

09 May 2021, 04:18

OK. You may get the idea from the code about how to do that. It would be something like the following change.

Code: Select all

Send {a down}
Sleep, 5000
Send {a up}{a down}
You can do it before or after the timers start.
TGX
Posts: 8
Joined: 24 Apr 2021, 02:46

Re: How do I run two sequences after each other and then loop back to the first

09 May 2021, 04:34

Thank you I will have a look.
I do realise that this is a help and assistance forum and not a "please do this for me forum" and when I had the issue I tried to add something like this but my attempts ended in it only pressing {a} and the rest of the script not running, or when I tried to crudely loop the {a} presses it wouldn't run at all.

Thank you again
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: How do I run two sequences after each other and then loop back to the first

09 May 2021, 05:11

You are welcome. Feel free to post your revised script for additional feedback.
TGX
Posts: 8
Joined: 24 Apr 2021, 02:46

Re: How do I run two sequences after each other and then loop back to the first  Topic is solved

09 May 2021, 05:17

So I'm not sure if this is what you had in mind, I had issues directly inserting the additions under the SoundBeep command, but I have added another SetTimer command for A and it seems to be working as I want it too.

Code: Select all

F10::Reload
F9::
SoundBeep, 1500
SetTimer, Stop, % -1000 * 60 * 60
SetTimer, A, 500
SetTimer, X, 200
Return

Stop:
SoundBeep, 1200
SetTimer, A, Off
Send {a up}
Sleep, 30000
SetTimer, X, Off
SoundBeep, 1000
Send {b down}
Sleep, 2000
Send {b up}
For k, v in [2, 5, 10, 2] {
 Send {Enter}
 Sleep, v * 1000
}
Send {Up}{Enter}
Sleep, 10000
Send {Esc}
Sleep, 500
Send {Esc}
Sleep, 500
Send {Esc}
Sleep, 500
Send {Enter}
Sleep, 5000
Gosub, F9
Return

A:
Send {a down}
Sleep, 5000
Send {a up}{a down}
Return

X:
Send x
Return

I can now leave it running and hopefully see the second sequence play out as expected, I will update either way.
If anyone can see anything obviously wrong with how I have added it please let me know, but as I say I believe it is working for me now so even it it is messy or inefficient I'm happy for now


EDIT:
After running it proper I found the 3 Esc actions weren't firing properly so I added sleeps and they are fine now.
Also, I realised that I needed the X action to continue past the A action for the 30 second wait after sequence 1 had finished so I moved a couple of things around. The above is the edited code with those changes and it works perfectly.

For those wondering and any future searches looking for the same thing, this is to grind kills in Final Fantasy IX
Last edited by TGX on 09 May 2021, 12:32, edited 1 time in total.
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: How do I run two sequences after each other and then loop back to the first

09 May 2021, 05:20

Good to hear. One thing to note is that a positive timer value will continue to cycle repeatedly; a negative timer value will execute once and then stop.
TGX
Posts: 8
Joined: 24 Apr 2021, 02:46

Re: How do I run two sequences after each other and then loop back to the first

09 May 2021, 05:31

That makes the Stop SetTimer code make more sense to me and will definitely help in the future for when I need to grind my terrible games. Thank you again and I hope you enjoy the rest of your weekend

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 47 guests