How to override "Pause Until" in case "until" is never met?

Preface:
I am using Keyboard Maestro to script movement in a video game mostly using the "Found image" condition.

The script involves getting a player from point A to point B, which involves a ton of moving images. The way I am managing the next click is by creating a "pause until found image" condition is met, which will ensure the script will click on the appropriate object once the image is located. It works magnificently.

However, I am trying to take it to the next level.

What I want to do:
I would like to somehow, at any point during the script, identify my player has logged out indicated by a change in image (login screen), and have keyboard maestro log me in and continue the script.

Problems:
My first thought was putting the whole script under an "Until" action.

Firstly, once the until action was met (in this case, the login screen image found), it didn't continue with the script and debugger deemed it complete.

Secondly, if my character logged out in the middle of a "pause until found image" action, then the script would be paused indefinitely until the found action.

Is there a way to indefinitely interject ALL actions if a condition is met (in this case, found image of login screen), which then allows me to execute another set of actions (in this case, logging me back in), and then resetting the loop?

Please let me know if I could be more clear on anything!

I would use a separate macro for this. Pausing until images are found can tax resources a fair bit, but staggering the image checks, even a little, can reduce this substantially. If you don't need to check for the login screen more than, say, every 1sec, you can use something like this:

Repeated Image Check.kmmacros (20 KB)

Macro screenshot

Obviously, you'd need to replace Finder with the the game app and add your actions to the If/Else group.

1 Like

hold up, I can run two different scripts at the same time simultaneously?

This is exactly what I needed! Thank you so much. I am at a lost for words lol, I had no idea I could do this!

1 Like

So, in the Repeated Image Check macro you gave me, one of the actions I need is to refer back to a loop in a separate macro. I'm aware of the "retry this loop", but is there a similar function where I can retry a loop in a separate macro? Would "Execute a Macro" work in this case?

I'm going to do some case-testing.

Sometimes if my character logs out, I notice the debugger sometimes paused the previously running macro, or cancels it depending on when the character logged out.

It it possible to cancel a macro after X amount of time has passed without a successful action? (In this case, I would set the time before the repeated image checker does its routine check)

By this I mean the original macro which moved my character from point A to B. It's a loop, which repeats indefinitely. A --> B --> A loop

Post your macros and I'll ty and help.

The one I posted will just repeatedly check the screen for a found image, every one second. What is the objective in referring to the other macro?

I can't know why this is without seeing your macro. If I were you, I'd do interval image checks rather than using pauses, as it's less taxing and can be run constantly while the game is running without the need for loops and without interruption.

Yes. Many action types have a timeout function, which can be accessed via the gear icon at its top-right.

So, the idea is that if something interrupts the macro, or the character glitches forcing it to log out, I use the repeated image checker to log back in. Depending on when the character logged out varies the actions I need to take when I log back in, in order to maintain an appropriate loop (which is easily resolved by an If/Else statement in my situation).

My question was that if I log back in and the previous macro is just "paused" and picks up from where it left off, it would pose an issue because that only happens when character logs out in between a "pause until" statement. For example, if the character logged out with the previous macro ALWAYS cancelled, then I would know the exact steps needed to retry the loop.

I see why this cannot work because then it would execute a macro every X amount of time it checked for the login screen.

I think you're absolutely right about this. I believe I would just have to go through my loop, find the points where I use "pause until" and replace them with a similar interval image check as the one you created, yeah?

I'm creating a simplified version of my macro so it's easy to read.

Loop.kmmacros (4.7 MB)

Here it is! Let me know if you need any clarification on any step. Thank you so much for your help btw. You're awesome for taking your time to check this out.

I removed a chunk at the end, which would log my character out and log it back in and retry the loop making it an infinite loop as long as nothing goes wrong.

I'm looking at your macro now and I have no idea what to make of it, as I don't know the game. What I will say is that as soon as I imported it, the Keyboard Maestro editor slowed to a crawl. There are a lot of images in there! It's by far the highest number of found image actions I've ever seen in a single macro! It seems like you're trying to entirely automate playing the game!

I'm intrigued by the random number components. What are they there for? It seems like you're using random numbers for almost every numeric function, which seems odd, but I'm sure you have your reasons.

Do all the click locations change during the game? If any of them are static, you could dramatically reduce the resource usage of the macro by clicking at fixed coordinates instead. I suppose this won't be possible if the order of events is random each time, but if there are patterns, you could just use clicks and pauses rather than pausing for found images all the time.

You could definitely make the macro easier to manage by subdividing it. For example, "if Image A is found, execute Submacro A". In this case, Submacro A would do a bunch of subsequent image checks.

Ultimately it's very hard for me to know what the most efficient ways to do all this are without knowing the game, but it does seem to me like you're doing a LOT of found image searches.

To the subject of this thread... Has the idea I previously posted solved the issue of logging back in?

1 Like

I'm laughing so hard right now reading the first two paragraphs, but yes -- you nailed it. I was trying to automate a portion of the game to completion and was successful :slight_smile: laughs maniacally

Also, I apologize for not warning you about the macro, yeah it's very intensive.

but to answer some questions:

simply ban-prevention from the game

No, they don't. In fact, I set the camera position in the game so that it always remains the same position. I have considered going back and making all the coordinates position based, but it becomes tricky if I want to use the loop on my external monitor. I suppose, I could just make two different macros.... shrugs in laziness

I'll do this for sure.

This was my original design, in fact. I started noticing randomness for certain instance load times which forced me to "pause until image" to account for randomness.

Hmm, I'm a little lost. By subsequent image checks do you mean do image checks for the next required image to click?

I had a feeling it'd be a difficult read since you need to know the game to create an efficient macro. I'll look back and see what I can reduce.

YES! ... sorta... well, it has partially. I am still working on a solution for getting the game loop (one I sent) to retry once I've logged back in.

I wrote this when you posted the first version via google drive. I was specifically talking about:

image

If this is found, you run a bunch of image actions.

I suppose perhaps this doesn't apply to the rest of the macro, but for something as long and involved as this is, you could still subdivide it to make it easier to manage. Entirely up to you.

How about...

Repeated Image Check.kmmacros (23 KB)

Macro screenshot

Oh yeah, that makes a ton of sense.

Voila! that'd be perfect. Hadn't even checked if there's a cancel a specific macro macro, keyboard maestro really has it all.

P.S.
Btw, currently replacing whichever "Find image" actions to position coordinate based clicks as we speak. Probably will be best in the long run.

1 Like

Without doubt, once you've spent some time with KM, you'll come back to this and have several :bulb:moments!

One thing I forgot to mention is that (and this almost goes without saying), if any game functions can be performed with keyboard controls rather than clicking on images, you might be able to leverage that too.

1 Like

Thank you for all your help man, you're truly a legend. I sincerely hope the best for you!

Every solution has worked out flawlessly :slight_smile:

1 Like