How to watch for and get out of stuck loop
Posted: Mon Jul 20, 2015 12:08 pm
I'm starting this thread to discuss an idea that was generated from within a different topic. I didn't want to hijack that thread so I'm starting this new thread.
Every once in a while, one of my characters gets stuck inside the Ancient Treasures minigame at the point where it is supposed to click the candlestick to transport out. When this happens, it seems the MM code is stuck in a loop where it thinks it clicked the candlestick and selected the option to transport out but did not and it sits there waiting (sometimes for hours until I notice it). If I manually click and exit the minigame, MM then resumes the waypoint where it should. So the question is... how can you watch for it getting stuck and force it's way out? Because the code being executed is stuck in a loop, no code you add to that waypoint can watch for the player being stuck. It would have to be in a separate MM window. So this got me to thinking... maybe I could create the following as a solution:
in my AT waypoint file, I add code that will launch a new, separate MM window, attach it to the same character, and all it will do is it's own loop of watching for player.X and player.Z. If those aren't constantly changing (for example, 30 seconds goes by and those values haven't changed) then the bot must be stuck. If those conditions are met, then I could either have it attempt to click the candlestick and get out, or I could have it do a recall and go to where it needs to go. Regardless of which route I choose to make it go, I would then have to make it detect whether it is now working or not, and decide also if I need to kill the other waypoint file/MM that is running and start a fresh one, or whether to take it over from the new one that was watching to unstick.
On top of that, If I wanted to be able to use this functionality from more than 1 waypoint, I would have to either build conditions within the "unsticking" waypoint, or make it where the recovery option is the exact same regardless of which waypoint it was running.
I'd like to hear anyone's input on this as I begin attempting to build such a function. There are a lot of you on these forums that are much better than me at coding so as I work on this I'll post some code and surely, I'll be asking for assistance.
Every once in a while, one of my characters gets stuck inside the Ancient Treasures minigame at the point where it is supposed to click the candlestick to transport out. When this happens, it seems the MM code is stuck in a loop where it thinks it clicked the candlestick and selected the option to transport out but did not and it sits there waiting (sometimes for hours until I notice it). If I manually click and exit the minigame, MM then resumes the waypoint where it should. So the question is... how can you watch for it getting stuck and force it's way out? Because the code being executed is stuck in a loop, no code you add to that waypoint can watch for the player being stuck. It would have to be in a separate MM window. So this got me to thinking... maybe I could create the following as a solution:
in my AT waypoint file, I add code that will launch a new, separate MM window, attach it to the same character, and all it will do is it's own loop of watching for player.X and player.Z. If those aren't constantly changing (for example, 30 seconds goes by and those values haven't changed) then the bot must be stuck. If those conditions are met, then I could either have it attempt to click the candlestick and get out, or I could have it do a recall and go to where it needs to go. Regardless of which route I choose to make it go, I would then have to make it detect whether it is now working or not, and decide also if I need to kill the other waypoint file/MM that is running and start a fresh one, or whether to take it over from the new one that was watching to unstick.
On top of that, If I wanted to be able to use this functionality from more than 1 waypoint, I would have to either build conditions within the "unsticking" waypoint, or make it where the recovery option is the exact same regardless of which waypoint it was running.
I'd like to hear anyone's input on this as I begin attempting to build such a function. There are a lot of you on these forums that are much better than me at coding so as I work on this I'll post some code and surely, I'll be asking for assistance.