2
votes

I am having a problem with my script which stops working properly, roughly after every 20-30 minutes of running. The problem seems to be with the loop that i have constructed and it stopping after that specific time. It's not the entire script that stops working because for example when i press another bind on caps lock it behaves normally. Furthermore when reloading the autohotkey script i get a message that "The script could not be reloaded." which I have never experienced before this problem with the loop.

So here's the code:

#IfWinActive Tibia
    SplashTextOn, 100, 40, Running, WASD
    WinMove, Running,, 1, 21

;SUSPEND AND INFORMATION===================================================
CapsLock::
Suspend
Toggle := !Toggle
if (Toggle = 0)
SplashTextOn, 90, 25, Running, WASD
  WinMove, Running,, 1, 27

if (Toggle = 1)
{
  SplashTextOn, 120, 40, NOT RUNNING, TYPING
  WinMove, NOT RUNNING,, 1497, 69
}
return


NumpadAdd::
MsgBox, You have 0.5 seconds to mouse over MAIN BACKPACK.
Sleep, 500
MouseGetPos, mainbpxpos, mainbpypos

MsgBox, You have 0.5 seconds to mouse over MAIN SLOT BACKPACK.
Sleep, 500
MouseGetPos, mainbpslotxpos, mainbpslotypos

MsgBox, You have 0.5 seconds to mouse over FOOD.
Sleep, 500
MouseGetPos, foodxpos, foodypos

MsgBox, You have 0.5 seconds to mouse over HAND.
Sleep, 500
MouseGetPos, handxpos, handypos

MsgBox, You have 0.5 seconds to mouse over BLANK on GROUND.
Sleep, 500
MouseGetPos, blankgroundxpos, blankgroundypos

MsgBox, You have 0.5 seconds to mouse over LAST BLANK.
Sleep, 500
MouseGetPos, lastblankxpos, lastblankypos

MsgBox, You have 0.5 seconds to mouse over MADE RUNES POS.
Sleep, 500
MouseGetPos, maderunesxpos, maderunesypos

MsgBox, You have 0.5 seconds to mouse over RUNBACK POSITION (OUT HOUSE).
Sleep, 500
MouseGetPos, runbackxpos, runbackypos

MsgBox, You have 0.5 seconds to mouse over RUN POSITION (IN HOUSE).
Sleep, 500
MouseGetPos, runxpos, runypos

InputBox, blankrunesleft, Blank runes left, Enter the blank runes left, , 200, 170

MsgBox, SCRIPT IS ABOUT TO RUN, CLOSE ALL BPS!

BreakLoop = 0
iamout = 0
enemy = 0
Loop
{
    if (BreakLoop = 1) {
        break
    }

    Loop, %blankrunesleft%
    {
        if (BreakLoop = 1) {
            break
        }
        SetMouseDelay, 5
        battleOne := ReadMemory(0x5C6950,"Tibia")
        ;Notify(battleOne)
        if (battleOne > 0) {
            MouseClick, left, runxpos, runypos
            Sleep, 30000
            MouseClickDrag, left, mainbpslotxpos, mainbpslotypos, blankgroundxpos, blankgroundypos
            Sleep, 400
            Send, {Control Down}g{Control Up}
            Sleep, 200
            Send, {Enter}
            Sleep, 5000
            iamout = 0
        }

        if (battleOne == 0) {
            if (iamout == 0) {
                MouseClick, right, mainbpxpos, mainbpypos
                Sleep, 200
                MouseClick, right, blankgroundxpos, blankgroundypos
                Sleep, 200
                MouseClickDrag, left, blankgroundxpos, blankgroundypos, mainbpslotxpos, mainbpslotypos
                Sleep, 200
                MouseClick, left, runbackxpos, runbackypos
                iamout = 1
                Sleep, 500
            }
        }

        mana := ReadMemory(0x5C682C,"Tibia")
        if (iamout == 1) {
            if (mana > 999) {
                MouseClick, right, foodxpos, foodypos
                Sleep, 60
                MouseClick, right, foodxpos, foodypos
                Sleep, 60
                MouseClick, right, foodxpos, foodypos
                Sleep, 100
                MouseClickDrag, left, lastblankxpos, lastblankypos, handxpos, handypos
                Sleep, 350
                Send, Adori Vita Vis
                Sleep, 100
                Send, {Enter}
                Sleep, 500
                MouseClickDrag, left, handxpos, handypos, lastblankxpos, lastblankypos
                Sleep, 350
                blankrunesleft -= 1
            }
        }
        if (iamout == 1) {
            if (blankrunesleft == 0) {
                Sleep, 100
                MouseClick, left, runxpos, runypos
                Sleep, 2000
                MouseClickDrag, left, mainbpslotxpos, mainbpslotypos, maderunesxpos, maderunesypos
                Sleep, 400
                MouseClick, right, mainbpxpos, mainbpypos
                Sleep, 500
                blankrunesleft = 20
                iamout = 0
            }
        }
    }
}

Esc::
BreakLoop = 1
return

#IfWinActive

Edit: To add up, I have restarted the pc and done 2 more tests on this script. The result was that it always stops running properly, after exactly 22 minutes. I have no idea what could be causing this, would appreciate any help

1
Are you sure it's not running? After 22 minutes, can you see the tray icon for the script disappear? If the script is running, the tray icon will visible in the system tray.bgmCoder
Yes, the script icon is still there and as i stated above when i try to reload it i encounter a message "The script could not be reloaded." Actually I have been guided to check whether it's the problem with the loops itself, by having a "debugging tricks" in my script. What I found out is that it actually isn't a problem with the loop itself because it keeps on running, when i encounter the script stopping working properly after these 22 minutes. I am actually wondering, because of the precise timing it happens every time, maybe it's some sort of memory problem ?Adrian
Ah, that is an odd problem. Can you use SystemExplorer and watch the list of processes to see if you can notice anything? It will show you when new process begin and what their commandlines are. I can't think of any reason why the script cannot reload unless there is a script error, or something is blocking autohotkey.exe (anti-virus, perhaps?)bgmCoder
Ok thanks i will download and install SystemExplorer for the next test, currently I have installed a different version of windows on my vmware machine and got the latest autohotkey version to see if the problem will occur. Coming back to your question, the machine that occurs the problem is not running any anti-virus at all, the only "security" it has is the windows firewall. ThanksAdrian
How is your script being launched and re-launched?bgmCoder

1 Answers

1
votes

Maybe if you rearranged things a little bit.

Move this to the top with your other hotkey routines; hotkeys should always be at the top of your script.

Esc::
BreakLoop = 1
return

put a return after the last {

This will keep the script from exiting when the loop ends.

As to your stopping every 22 minutes - is it possible that this is the length of the loop sequence? Since the timing seems consistent, you ought to be able to find the issue by keeping an eye out for simultaneous events.

Also, so can you tell what line the script is on when it says it won't reload? If you right-click on the tray icon and choose "Open" you will be able to see the status of the lines being processed. That sort of debuggin method also shows you the time each line took to process and run. That may be very valuable in your case.