[Edit by Moderator to replace "script" with "macro"]
Basically I use KM Macros to carry out repetitive tasks in a MMO I play, to level me up.
Occasionally the Macro will missclick, causing a whole range of issues, which essentially stops the Macro from progressing and repeating.
I was simply wondering if there was a way or a command to make it so if a Macro Action failed, or there was no clicking/input for a set amount of time, that the Macro restarted (or carried out some commands and then restarted)?
I hope you don't mind that I have revised your topic title to better reflect the question you have asked.
FROM: Question about scripts I use for a MMO
TO: How Do I Handle Macro Action Failures Used for Clicking in a MMO?
This will greatly help you attract more experienced users to help solve your problem, and will help future readers find your question, and the solution.
Also, I have assumed that by "script" you mean a KM "Macro" or "Macro Action", and have changed your post accordingly. If I am incorrect, and you really did mean "script" (as in AppleScript or Shell Script, etc.) then let me know and I will restore your OP.
Sounds very familiar. In the times I played WoW I’ve written and used macros to automate things while I was AFK.
Games like that (or probably games in general) are hard to script, so I (mainly) had to rely on Found Image conditions. Naturally these will fail when context changes (for example something unexpected happens on screen).
To catch the change or to prevent possible damage I did this:
Another Found Image condition test after the action — or periodically
If it fails, either…
pause for a certain time or abort, or
send a mail to me, so I could check the current screen from remote and adjust either the macro or the game context
Just an example. What —and how— you have to test for, will depend on the situation.
That's exactly what I mean. Spot on. I use it for Old School RuneScape to automise monogamous tasks (e.g. levelling up Fishing.)
Those issues you have are the same with me, as I use Found Image conditions too. Sometimes, yeah, something unexpected will happen on the screen. The thing with it is a lot of my scripts are extremely long and to trying to predict every possibility of failure and making such adjustments for it would be an almost impossible task, simply because it has the possibility of failing anywhere; often due to server lag.
I was driving home and thinking, what if there was an option, if the click on found image fails and/or times out, it does a certain set of steps to get the character back to the start, and then simply resets the macro from the beginning. Like an "If/Else". E.g. "If" the scripts fails, teleport to the start, and continue from the beginning of "Else".
For example, if I set each "Click at Found Image" to have a timeout of 15/20 seconds; say if it cannot find the image to click on, it stops the script: "Timeout Aborts Macro". Once the script has stopped or "inactive?", it does a few steps to reset the character in game to the beginning, then executes the macro to start again.
Also keep in mind that ActionResult doesn’t always work as you might have expected.
For example: If you call a http URL and the page doesn’t exist, you most likely get back an “error” 404. For you this is an error, but the URL action still has succeeded.
If you’re not familiar with it, I would build a little test macro for each type of action you’re planning to use it with:
Action A followed by a Display %ActionResult%. Then make action A succeed and fail (in your terms), and see if ActionResult returns what you expect.
Have temporarily got a solution for this. I have shortened the timeout to 5 seconds for each "Pause Until" and also have cancelled the "Failure Aborts Macro" for both the "Pause Until" and the "Click at Found Image". This means if any action fails during the repeat process, it circles around and starts again.