Need a Lead for Submacro


I'm looking for some ideas to get me started and point me in the right direction for a submacro that will be implemented into my main macro. The macro is for a game, which sometimes can be obstructed by various things. I want this submacro to solve the issues when it occurs.

The action being performed in the game involves clicking a specific position within the spellbook interface, which switches the interface to the inventory to cast the spell onto the item within the inventory. When the item is clicked, it switches back to the spell book to repeat the process. This process occurs every couple seconds and repeats over and over. If it helps, the spell is yellow and the item is blue.

The following errors can occur with halt the process:
*I can be logged out automatically for various reasons
*The game might lag, not register the spell, and consequently perform a different task which misplaces the item
*I might run out of the other items necessary to cast the spell

Essentially, I need the macro to detect if this process (switching between interfaces) comes to a stop. Then, I need to implement corrective actions to fix the problem (Autologged out, bolts inadvertently moved, ran out of runes). If the macro detects the halt in the constant switching of interfaces, I can then set actions for the script to look to see if I'm logged out, look to see if the bolts have been misplaced, or look to see if I ran out of a certain item.

If anyone can point me in the right direction in terms of functions, etc., that would be awesome.

I tried for hours and hours trying to get that found image on screen thing to work. Nothing. much as I love automation, maybe automating a game defeats the purpose?